Question one hundred and twelve: Legal identifier of C language (2)

Source: Internet
Author: User

[Plain] Description
 
Enter a string to check whether it is a valid identifier of C.
 
Input
 
The input data contains multiple test instances. The first line of the data is an integer n, indicating the number of test instances, followed by n rows of input data, each line is a string of no more than 50 characters.
 
Output
 
Output a row of input data for each group. If the input data is a valid identifier of C, "yes" is output; otherwise, "no" is output ".
 
 
Sample Input
 
 
3
12ajf
Fi8x_a
Ff ai_2
 
Sample Output
 
 
No
Yes
No

Description

Enter a string to check whether it is a valid identifier of C.

Input

The input data contains multiple test instances. The first line of the data is an integer n, indicating the number of test instances, followed by n rows of input data, each line is a string of no more than 50 characters.

Output

Output a row of input data for each group. If the input data is a valid identifier of C, "yes" is output; otherwise, "no" is output ".


Sample Input


3
12ajf
Fi8x_a
Ff ai_2

Sample Output


No
Yes
No
 


[Plain] # include <stdio. h>
# Include <string. h>
 
Int main ()
{
Int I;
Int flag;
Int num;
Int length;
Char string [101];
 
Scanf ("% d", & num );
Getchar ();
 
While (num --)
{
Gets (string );
Length = strlen (string );
Flag = 1;
 
If (string [0] = '_' | (string [0]> = 'A' & string [0] <= 'Z ') | (string [0]> = 'A' & string [0] <= 'Z '))
{
For (I = 0; I <length; I ++)
{
If (string [I] = '_' | (string [I]> = 'A' & string [I] <= 'Z ') | (string [I]> = 'A' & string [I] <= 'Z ') | (string [I]> = '0' & string [I] <= '9 '))
{
Flag = 1;
}
Else
{
Flag = 0;
}
 
If (flag = 0)
{
Break;
}
}
}
Else
{
Flag = 0;
}

 
If (flag)
{
Printf ("yes ");
}
{
Printf ("no ");
}
 
If (num> 0)
{
Printf ("\ n ");
}
}
 
Return 0;
}

# Include <stdio. h>
# Include <string. h>

Int main ()
{
Int I;
Int flag;
Int num;
Int length;
Char string [101];

Scanf ("% d", & num );
Getchar ();

While (num --)
{
Gets (string );
Length = strlen (string );
Flag = 1;

If (string [0] = '_' | (string [0]> = 'A' & string [0] <= 'Z ') | (string [0]> = 'A' & string [0] <= 'Z '))
{
For (I = 0; I <length; I ++)
{
If (string [I] = '_' | (string [I]> = 'A' & string [I] <= 'Z ') | (string [I]> = 'A' & string [I] <= 'Z ') | (string [I]> = '0' & string [I] <= '9 '))
{
Flag = 1;
}
Else
{
Flag = 0;
}

If (flag = 0)
{
Break;
}
}
}
Else
{
Flag = 0;
}

If (flag)
{
Printf ("yes ");
}
{
Printf ("no ");
}

If (num> 0)
{
Printf ("\ n ");
}
}

Return 0;
}

 

 
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.