HDOJ 2024 C language legal identifiers

Source: Internet
Author: User

C-Language legal identifiers Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 37056 Accepted Submission (s): 14897



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

Authorlcy
SOURCEC Language programming Exercises (iv)
Recommendlcy | We have carefully selected several similar problems for you:2025 2026 2021 2027 2030



--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
This topic first need to know what is the C language legal identifier:

(1), the first element can only be underlined or letters,
(2), elements except the first element can only be numbers, underscores and letters)

First determine whether the first character conforms to the opening rule, and then each character is judged one after the other.

AC Code:

#include <iostream> #include <string>using namespace Std;int main () {string A;int n;cin >> N;getchar (); while (n--) {getline (cin, a); bool flag = TRUE;IF (!) ( A[0] = = ' _ ' | | (' A ' <= a[0] && a[0] <= ' z '))) {flag = False;cout << "no" << endl;continue;} for (int i = 0; i < a.size (); i++) {if (!) ( A[i] = = ' _ ' | | (A[i] >= ' 0 ' &&a[i] <= ' 9 ') | | (' A ' <= a[i] && a[i] <= ' Z ') | | (' A ' <= a[i] && a[i] <= ' z '))) {flag = False;cout << "no" << Endl;break;}} if (flag) cout << "yes" << Endl;} return 0;}




 

Hdoj 2024 C language legal identifier

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.