gaosshun

2024 C语言合法标识符

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


code:
 1 Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
 2 
 3 #include<cmath>
 4 #include<iostream>
 5 using namespace std;
 6 
 7 bool judge(string &s)
 8 {
 9     if(!((s[0]>=\'a\'&&s[0]<=\'z\')||(s[0]>=\'A\'&&s[0]<=\'Z\')||s[0]==\'_\'))
10         return 0;
11     for(int i=1;s[i]!=0;i++)
12     {
13         if(!((s[i]>=\'a\'&&s[i]<=\'z\')||(s[i]>=\'A\'&&s[i]<=\'Z\')||s[i]==\'_\'||(s[i]<=\'9\'&&s[i]>=\'0\')))
14             return 0;
15     }
16     return 1;
17 }
18 
19 int main(){
20     int n,m,c;
21     int i,j,k;
22     string s;
23     cin >> n;
24     getchar();
25     for(i=0;i<n;i++)
26     {
27         getline(cin, s);
28         if(judge(s))
29             cout << "yes"<<endl;
30         else
31             cout << "no"<<endl;
32     }
33     return 0;
34 }

 


分类:

技术点:

相关文章:

  • 2021-07-02
  • 2022-01-10
  • 2022-01-19
  • 2021-12-08
  • 2022-01-17
猜你喜欢
  • 2022-02-07
  • 2022-01-29
  • 2022-03-07
  • 2021-12-21
  • 2021-12-23
  • 2022-01-07
  • 2021-11-23
相关资源
相似解决方案