当前位置: 代码迷 >> 综合 >> XTU OJ 1234 Legal Identifier
  详细解决方案

XTU OJ 1234 Legal Identifier

热度:71   发布时间:2023-12-04 21:32:19.0
//首先特判掉第一个为数字的 
//然后从第一个(a1)开始判断,锁定串长遍历,如果出现就Break,如果没有则继续。
//strcmp()函数。
#include<stdio.h>
#include<string.h>
char a[34][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"} ;
char num[34];
int  main()
{int k;scanf("%d",&k);while(k--){int flag=1;scanf("%s",num);int n=strlen(num);for(int i=0;i<n;i++){if(num[0]>='0'&&num[0]<='9'){flag=0;break;}if(num[i]>='0'&&num[i]<='9'||num[i]>='a'&&num[i]<='z'||num[i]>='A'&&num[i]<='Z'||num[i]=='_'){continue;}else{flag=0;break;}}if(flag){if(n>=2&&n<=8){for(int i=0;i<32;i++){if(strcmp(num,a[i])==0){flag=0;break;}else continue;}}}if(flag==0)    printf("No\n");else         printf("Yes\n");}return 0;
}

  相关解决方案