ZZULIOJ.1138: C語言合法識別符號
阿新 • • 發佈:2018-11-25
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;
}