C-Language legal identifiersTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 44597 Accepted Submission (s): 17933
Problem 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 Input
312ajffi8x_aff ai_2
Sample Output
Noyesno
#include <stdio.h>
#include <string.h>
Main ()
{int a,i,j,b;
Char s[100];
scanf ("%d", &b);
GetChar ();
while (b--)
{a=1;
Gets (s);
if ((s[0]< ' a ' &&s[0]> ' Z ') && (s[0]!= ' _ ')) | | s[0]< ' A ' | | S[0]> ' Z ')
{
printf ("no\n");
Continue
}
J=strlen (s);
for (i=1;i<j;i++)
if ((s[i]>= ' a ' &&s[i]<= ' z ') | | (s[i]>= ' 0 ' &&s[i]<= ' 9 ') | | (s[i]>= ' A ' &&s[i]<= ' Z ') | | (s[i]== ' _ '))
a++;
if (A==J)
printf ("yes\n");
Else
printf ("no\n");
}
return 0;
}
C-Language legal identifiers