hdu 2024 C语言合法标识符

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2024

题目大意:c语言的合法标识符由字母、下划线、数字这三个方面组成,但开头必须是字母或下划线。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。

 1 #include <stdio.h>
 2 int main (void)
 3 {
 4     int n,i,m,t,j;
 5     char a[64],c;
 6     scanf("%d%c",&n,&c);
 7     while (n--)
 8     {
 9         t=0;
10         gets(a);
11         //getchar();
12         if ((a[0]<='Z'&&a[0]>='A')||(a[0]>='a'&&a[0]<='z')||a[0]=='_')
13         {
14             for(j=1; a[j]!=''; j++)
15             {
16                 if(!((a[j]<='z'&&a[j]>='a')||(a[j]<='Z'&&a[j]>='A')||(a[j]>='0'&&a[j]<='9')||a[j]=='_'))
17                 {t=1;break;}
18             }
19             if(t==0)
20                 printf("yes
");
21             else
22                 printf("no
");
23         }
24         else
25             printf("no
");
26     }
27     return 0;
28 }
原文地址:https://www.cnblogs.com/qq-star/p/3843727.html