Description Enter a string to determine whether it is a valid identifier for C. Input data contains multiple test instances, the first row of the data is an integer n, which indicates the number of test instances, followed by n rows of input data, each of which is a string of not more than 50 in length. Output outputs one row for each set of input data. If the input data is a valid identifier for C, output "yes", otherwise, output "no". Sample input312ajffi8x_aff ai_2sample Outputnoyesnohintsource
The code is as follows:
#include "stdio.h" int main () { int n; scanf ("%d", &n); GetChar (); while (n--) { char a[51]; int k,i=0,b=0; for (i=0; i<51; i++) { scanf ("%c", &a[i]); if (a[i]== ' \ n ') { k=i; break; } } if ((a[0]>=65 && a[0]<=90) | | a[0]==95 | | (a[0]>=97 && a[0]<=122)) {for (i=0; i<k; i++) { if (a[i]>=65 && a[i]<=90) | | a[i]==95 | | (a[i]>=97 && a[i]<=122) | | (a[i]>=48 && a[i]<=57)) b++; else break ; } } if (b==k) printf ("yes\n"); else printf ("no\n"); } return 0;}
Operation Result:
Learning experience:
Continue in the C language answer, C in writing although more cumbersome than C + +, but do not know why I feel like to use C;
Identifier I understand roughly what it is. But the standard format I really do not know, had to Baidu,
Identifiers consist of three aspects of letters, underscores, and numbers, but must begin with letters or underscores.
Then on AC, although there is reference to other people's code, fortunately, learned a hand.
Ytuoj-c Language Legal identifiers