Hdoj Title Address: Portal
C-Language legal identifiersTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 59528 Accepted Submission (s): 23541
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> #include <map> #include <iostream> #include < Algorithm>using namespace Std;int Main () { int n; string S; cin>>n; int flag=1; GetChar (); while (n--) { flag=1; Getline (cin,s); if (S.size () ==0) { printf ("no\n"); flag=0; } else if (! ( (s[0]>= ' A ' &&s[0]<= ' z ') | | (s[0]>= ' A ' &&s[0]<= ' Z ') | | s[0]== ' _ ')) { printf ("no\n"); flag=0; } else{for (int i=1;i<s.size (); i++) { if ((s[i]>= ' 0 ' &&s[i]<= ' 9 ') | | s[i]== ' _ ' | | (s[i]>= ' A ' &&s[i]<= ' z ') | | (s[i]>= ' A ' &&s[i]<= ' Z '))) { }else{ flag=0; printf ("no\n"); Break ; }}} if (flag) printf ("yes\n");} }
ACM--HDOJ 2024--c Language Legal identifier--string