Problem Description
输入一个字符串,判断其是否是C的合法标识符。
Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input
3
12ajf
fi8x_a
ff ai_2
Sample Output
no
yes
no
AC代码:
#include<stdio.h> #include<string.h> void main() { int n=0,i,j,k,s,x,y,z; char a[55]; char b[33][10]={"auto","break","case","char","const","continue","default","do","double","else","enum","extern","float","for","goto","if","int","long","register","return","short","signed","sizeof","static","struct","switch","typedef","union","unsigned","void","volatile","while"}; scanf("%d",&n); getchar(); for(i=1;i<=n;i++) { gets(a); s=strlen(a); x=y=z=1; if(a[0]==\'_\'||(a[0]>=\'A\'&&a[0]<=\'Z\')||(a[0]>=\'a\'&&a[0]<=\'z\')) { x=0; for(j=0;j<32;j++) if(!strcmp(a,b[j])) z=0; for(j=1;j<s;j++) { if(a[j]==\'_\'||(a[j]>=\'A\'&&a[j]<=\'Z\')||(a[j]>=\'a\'&&a[j]<=\'z\')||(a[j]>=\'0\'&&a[j]<=\'9\')) continue; else y=0; } } // printf("%d%d%d",x,y,z); if(x==0&&y==1&&z==1) printf("yes\n"); else printf("no\n"); } }