06: valid C identifier, 06 identifier
06: Legal C identifier
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
.
C language identifier requirements:
1. Non-reserved words;
2. Only letters, numbers, and underscores (_) are allowed.
3. Do not start with a number.
-
Input
-
A line that contains a string. The string does not contain any blank characters and cannot exceed 20 characters.
-
Output
-
A row. If it is a valid identifier of the C language, yes is output; otherwise, no is output.
-
Sample Input
-
RKPEGX9R;TWyYcp
-
Sample output
-
no
-
Source
-
Introduction to computing of Peking University 06 psychological and Information Management Final Examination
-
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 char a[10001]; 6 int main() 7 { 8 gets(a); 9 int l=strlen(a);10 int flag=0;11 12 for(int i=0;i<l;i++)13 { 14 if(i==0)15 {16 if(a[0]>=48&&a[0]<=57)17 { 18 cout<<"no";19 return 0;20 }21 }22 if((a[i]==95)||(a[i]>=48&&a[i]<=57)||(a[i]>=65&&a[i]<=90)||(a[i]>=97&&a[i]<=122))23 flag=0;24 else flag=1;25 if(flag==1)26 {27 cout<<"no";28 return 0;29 }else continue;30 }31 32 cout<<"yes";33 return 0;34 }