C-Language legal identifiersTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 42681 Accepted Submission (s): 17117
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
problem : The topic is very simple, no difficulty and skill. Focus on the C language legal identifiers . definition: In the high-level computer language, the valid character sequences used to name variables, symbolic constant names, functions, arrays, types, etc. are collectively referred to as identifiers. Note: 1. The C language specifies that identifiers can only consist of letters, numbers, and underscores of 3 characters, and that the 1th character must be a letter or an underscore. 2. The compilation system considers uppercase and lowercase letters to be two different characters.
The AC code is as follows:
#include <stdio.h> #include <string.h>int main () {int Len,n,i;char str[55];scanf ("%d", &n); GetChar (); /here to absorb character while (n--) {gets (str); if (str[0]<65| | str[0]>122) &&str[0]!= ' _ ') printf ("no\n"); else{ int K=0;len=strlen (str); for (i=1;i<len;i++) {if (str[i]<48| | (str[i]<65&&str[i]>57) | | str[i]>122) &&str[i]!= ' _ ') {K=1;break;}} if (!k) printf ("yes\n"), Else printf ("no\n");}} return 0;}
HDOJ 2024 C language legal identifiers (water questions, speaking identifiers)