65,211
社区成员
发帖
与我相关
我的任务
分享#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main()
{
fstream fin;
vector< vector<string> >result;
string str;
fin.open("in.txt", ios::in);
while (!fin.eof())
{
char left[32]={0}, right[32]={0};
if (!getline(fin, str)) break;
sscanf(str.c_str(), "%s : %s", left, right);
right[strlen(right)-1]=0;
printf("%s : %s\n", left, right);
//自己写到某个结果中去;
}
fin.close();
return 0;
}#include<iostream>
#include<fstream>
using namespace std;
const int size=100;
char b[26];
char a[size][size];
void OutputF(int i,int x)
{
if(a[i][x]>=97&&a[i][x]<=122) //a[i][x]为终结符时
cout<<a[i][x]<<"}"<<endl;
else
if(a[i][x]==36) //$的asc值为36
{
cout<<a[i][x]<<"$,";
OutputF(i,x+1);
}
else
{
for(int l=0;l<size;l++)
while(a[i][x]==a[l][0])
OutputF(l,x);
}
}
int main()
{
ifstream file("a.txt");
if(!file)
{
cout << "a.txt 放到生成的EXE在的目录下\n";
return 1;
}
for(int i=0;i<size;i++) //输入
{
for(int j=0;j<size;j++)
{
file>>a[i][j]; //这从文件流输入
if(a[i][j]!=35) //#对应35
{
if(a[i][j]>=65&&a[i][j]<=90) //a[i][j]为非终结符
b[i]=a[i][j]-65;
if(a[i][j]==59)break; //;对应 59
}
else break;
}
}
for(i=0;i<size;i++) //first
{
if(a[i][0]>=65&&a[i][0]<=90&&a[i][1]==58) //58对应 :
{
cout<<"First(";
for(int j=2;j<size;j++)
if(a[i][j]!=59)
cout<<a[i][j];
cout<<")={";
}
int x=2;
OutputF(i,x);
}
file.close();
system("Pause");
return 0;
}
#include <string>
#include <map>
#include <vector>
#include "stdio.h"
using namespace std;
bool ParseProduction(string& Symbol, string& Product){
char c = 0;
Symbol.clear();
Product.clear();
while(!isalpha(c)){
if(scanf("%c", &c) == EOF){
return false;
}
}
Symbol += c;
while(true){
c = getchar();
if(!isalpha(c)){
break;
}
Symbol += c;
}
while(c != ':'){
c = getchar();
}
c = 0;
while(!isalpha(c) && c != ';'){
c = getchar();
}
if(c != ';'){
Product += c;
while(true){
c = getchar();
if(!isalpha(c)){
break;
}
Product += c;
}
while(c != ';'){
c = getchar();
}
}
return true;
}
int GetIndex(map<string, int>& Map, const string& String){
int Size = Map.size();
if(Map.find(String) == Map.end()){
Map[String] = Size;
return Size;
}
else{
return Map[String];
}
}
int main()
{
freopen("text.txt","r",stdin);
vector<vector<string> > vvProduct;
map<string, int> Map;
string Symbol, Production;
while(ParseProduction(Symbol, Production)){
int Index = GetIndex(Map, Symbol);
if(Index >= vvProduct.size()){
vvProduct.resize(Index + 1);
}
vvProduct[Index].push_back(Production);
}
//test
//map<string, int>::iterator it = Map.begin();
//int Pos = 0;
//while(it != Map.end()){
// printf("%s : ", (*it).first.c_str());
// Pos = (*it).second;
// const vector<string>& vProduct = vvProduct[Pos];
// int Size = vProduct.size();
// int i;
// for(i = 0 ; i < Size ; ++i){
// printf("(%s) ", vProduct[i].c_str());
// }
// printf("\n");
// ++it;
//}
return 0;
}
#include<iostream>
#include<fstream>
using namespace std;
const int size=100;
char b[26];
char a[size][size];
void OutputF(int i,int x)
{
if(a[i][x]>=97&&a[i][x]<=122) //a[i][x]为终结符时
cout<<a[i][x]<<"}"<<endl;
else
if(a[i][x]==36) //$的asc值为36
{
cout<<a[i][x]<<"$,";
OutputF(i,x+1);
}
else
{
for(int l=0;l<size;l++)
while(a[i][x]==a[l][0])
OutputF(l,x);
}
}
int main()
{
ifstream file("a.txt");
if(!file)
{
cout<<"a.txt 放到生成的EXE在的目录下\n";
return 1;
}
for(int i=0;i<size;i++) //输入
{
for(int j=0;j<size;j++)
{
cin>>a[i][j];
if(a[i][j]!=35) //#对应35
{
if(a[i][j]>=65&&a[i][j]<=90) //a[i][j]为非终结符
b[i]=a[i][j]-65;
if(a[i][j]==59)break; //;对应 59
}
else break;
}
}
for(int i=0;i<size;i++) //first
{
if(a[i][0]>=65&&a[i][0]<=90&&a[i][1]==58) //58对应 :
{
cout<<"First(";
for(int j=2;j<size;j++)
if(a[i][j]!=59)
cout<<a[i][j];
cout<<")={";
}
int x=2;
OutputF(i,x);
}
file.close();
system("Pause");
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char buff[100];
memset(buff,0,sizeof(buff));
fstream fout;
fout.open("text.txt",ios::out);
cout<<"Please input your data, end with *"<<endl;
cin.get(buff,sizeof(buff),'*');//提取数据,以*结束
fout.write(buff,strlen(buff));
fout.close();
return 0;
}
/*
Please input your data, end with *
S:AB;
S:bC;
A:;
B:;
B:aD;
C:AD;
C:b;
D:aS;
D:c;
*
*/