ACM--HDOJ 2024--c Language Legal identifier--string

Source: Internet
Author: User


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

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.