ZZULIOJ.1138: C语言合法标识符

1138: C语言合法标识符

题目描述

输入一个字符串,判断其是否是C的合法标识符。C语言中规定标识符只能由字母、数字和下划线3种字符组成,且第一个字符必须为字母或下划线。

输入
输入一个长度不超过50的字符串。

输出
如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。

样例输入
8fixafghgjhjhjyuyuyyuyuyu

样例输出
no

#include<stdio.h>
#include<string.h>
int main()
{
    int i,t=1,m;
    char ch,str[50];
    gets(str);
    m=strlen(str);
    if(str[0]>='0'&&str[0]<='9')
    {
        printf("no");
    }
    else if(str[0]=='_'||(str[0]>='a'&&str[0]<='z')||(str[0]>='A'&&str[0]<='Z'))
    {
        for(i=1;str[i]!='\0';i++)
        {
            ch=str[i];
            if((ch>='0'&&ch<='9')||ch=='_'||(ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
            t++;
        }
        if(m==t) printf("yes");
        else printf("no");
    }
    else printf("no");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43705195/article/details/84350071