C-Language legal identifiersTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 39100 Accepted Submission (s): 15614
problem Descriptionenter a string to determine whether it is a valid identifier for C.
InputThe input data contains multiple test instances, and the first row of the data is an integer n, representing the number of test instances, followed by n rows of input data, each of which is a string of no more than 50 length.
Outputfor each set of input data, output one line. If the input data is a valid identifier for C, output "yes", otherwise, output "no".
Sample Input
312ajffi8x_aff ai_2
Sample Output
Noyesnoproblem-solving ideas:isalpha function Link: http://blog.163.com/caipeipei_love%40126/blog/static/25966032201032784630227/ isalnum function Link: http://see.xidian.edu.cn/cpp/html/112.html Source code:#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h>int main () { int i,n,f; Char str[51]; scanf ("%d", &n); GetChar (); while (n--) {gets (str); f=1; if (str[0]!= ' _ ' &&!isalpha (Str[0])) f=0; I=1; while (str[i]!= ' && f==1) {if (str[i]!= ' _ ' &&!isalnum (Str[i])) f=0; i++; } if (f==0) printf ("no\n"); else printf ("yes\n"); } system ("Pause"); return 0; }
C-Language legal identifiers