Ytuoj-c Language Legal identifiers

Source: Internet
Author: User

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 input312ajffi8x_aff  ai_2sample Outputnoyesnohintsource


The code is as follows:

#include "stdio.h" int main () {    int n;    scanf ("%d", &n);    GetChar ();    while (n--)    {        char a[51];        int k,i=0,b=0;        for (i=0; i<51; i++)        {            scanf ("%c", &a[i]);            if (a[i]== ' \ n ')            {                k=i;                break;            }        }        if ((a[0]>=65 && a[0]<=90) | | a[0]==95 | | (a[0]>=97 && a[0]<=122))        {for            (i=0; i<k; i++)            {                if (a[i]>=65 && a[i]<=90) | | a[i]==95 | | (a[i]>=97 && a[i]<=122) | | (a[i]>=48 && a[i]<=57))                    b++;                else break                     ;            }        }        if (b==k)            printf ("yes\n");        else         printf ("no\n");    }    return 0;}


Operation Result:

Learning experience:

Continue in the C language answer, C in writing although more cumbersome than C + +, but do not know why I feel like to use C;

Identifier I understand roughly what it is. But the standard format I really do not know, had to Baidu,

Identifiers consist of three aspects of letters, underscores, and numbers, but must begin with letters or underscores.

Then on AC, although there is reference to other people's code, fortunately, learned a hand.

Ytuoj-c Language Legal identifiers

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.