1、#includecstdiocstringusing namespace std;int k=0;struct word char name10; int kind; word1000;char key3510= scanf,shortintlongfloatdoublecharstructunion, printftypedefconstunsignedsignedexternregisterstaticvolatilevoidifelseswitchcasefordowhilegotocontinuebreakdefaultsizeofreturnincludebool ;bool cmp
2、(char a) int i; for(int k=0; k35; k+) if(strcmp(a,keyk)=0) return 1; return 0;int main() #ifdef LOCAL freopen(in.txt, r, stdin);out.txtw, stdout); #endif int p,q,flag; char a1000,b10,ch; while(gets(a) p=0; int len=strlen(a); while(p=a&chAZ)|ch=_ flag=0; q=0; while(ch|(ch09) flag=1; bq+=ch; if(flag=1
3、) strcpy(wordk.name,b); wordk+.kind=1; else if(flag=0) if(ch=|ch= wordk+.kind=2; else if(cmp(b)=1) wordk+.kind=3; else else if(ch- int t=p-1; if(atat b0=; b1=ch; wordk+.kind=5; ch=a+p;. else if(ch=(),:)/ch=| b0=ch; wordk+.kind=4;%+*/ b0=b1=! b1=| for(int i=0; ik; i+) switch(wordi.kind) case 1: print
4、f(标识符,); break; case 2:(常量, case 3:(关键字, case 4:(界符, case 5:(运算符,%s)n,wordi.name); int a1=0,a2=0,a3=0,a4=0,a5=0;ii+) if(wordi.kind=1) a1+; else if(wordi.kind=2) a2+; else if(wordi.kind=3) a3+; else if(wordi.kind=4) a4+; else if(wordi.kind=5) a5+;标识符:%dn常量:%dn关键字:%dn界符:%dn运算符:%dn,a1,a2,a3,a4,a5);运行结果: