码迷,mamicode.com
首页 > 编程语言 > 详细

C语言合法标识符

时间:2014-11-23 22:57:22      阅读:627      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   sp   for   数据   

 1 //Problem Description
 2 //输入一个字符串,判断其是否是C的合法标识符。
 3 //
 4 //
 5 //Input
 6 //输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
 7 //
 8 //
 9 //Output
10 //对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
11 
12 #include <stdio.h>
13 #include <string.h>
14 int main ()
15 {
16     int n;
17 
18     while (scanf( "%d", &n )!=EOF)
19     {
20           getchar();
21        while(n--)
22         {
23             char a[100];int k=0,tag=0,s=1;
24             gets(a);
25             
26             k=strlen(a);
27             for (int i = 0; i < k; ++i )
28             {
29                 if(i==0)
30                 {
31                     if( ( a[i] < a && a[i] > _ ) || a[i] > z  || a[i]<A || ( a[i]<_ && a[i]>Z ))
32                     {
33                        tag=1;
34                     }
35                 }
36                 if(i>0&&tag!=1)
37                 {
38 
39 
40                     if( a[i] == _ || ( a[i] >= A && a[i] <= Z ) || ( a[i] >= a && a[i] <= z ) || ( a[i] >= 0 && a[i] <= 9 ))
41                     {
42                         s=s+1;
43                     }
44 
45                 }
46 
47 
48             }
49             
50                         if(s==k)
51                         printf("yes");
52                         if(s!=k||tag==1)
53                         printf("no");
54             printf("\n");
55 
56         }
57     }
58 }

 

C语言合法标识符

标签:des   style   blog   io   ar   color   sp   for   数据   

原文地址:http://www.cnblogs.com/lonelysky/p/4117508.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!