1413. C language legal identifier

Title description

Enter a string to determine whether it is a legal identifier for C.

enter

Enter a string of no more than 50 characters.

Output

If the input data is a legal identifier of C, output "yes", otherwise, output "no".

Sample input

8fixafghgjhjhjyuyuyyuyuyu

Sample input

no

Sample output

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//字母1,数字2,下划线3
int panduan(char a)//合法
{
    
    
    int ret=-1;
    if(a>='a'&&a<='z')
        ret=1;
    else if(a>='A'&&a<='Z')
        ret=1;
    else if(a>='0'&&a<='9')
        ret=2;
    else if(a=='_')
        ret=3;
    return ret;
}

int main()
{
    
    
    char a[100];
    int i,m;
    gets(a);
    m=strlen(a);
    if(panduan(a[0])==1||panduan(a[0])==3)//对
    {
    
    
        for(i=1;i<m;i++)
        {
    
    
            if(panduan(a[i])==-1)
            {
    
    
                printf("no");
                return 0;
            }
        }
        printf("yes");
    }
    else
    {
    
    
        printf("no");
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_51800059/article/details/112059684