本文最后更新于35 天前,其中的信息可能已经过时,如有错误请发送邮件到suzhech@gmail.com
#include<stdio.h>
#include<string.h>
#include<ctype.h>
const char keyword[32][10] =
{
"int","float","double","char","short","long","signed","unsigned",
"void","auto","register","static","extern","typedef","if","else",
"switch","case","default","for","while","do","break","continue",
"goto","return","const","union","struct","enum","volatile","sizeof"
};
int main()
{
char s[53];
while (gets(s) != NULL)
{
int jud = 1;
for (int i = 0; i < 32; i++)
{
if (!strcmp(s, keyword[i]))
{
jud = 0;
}
}
int len = strlen(s);
if (s[0]>='0'&&s[0]<='9')
{
jud = 0;
}
for (int i = 0; i < len && jud == 1; i++)
{
if (!((s[i] >= '0' && s[i] <= '9') || (s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z') ||s[i] == '_'))
{
jud = 0;
}
}
if (jud == 1)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
return 0;
}
注意:因为使用了gets函数,所以很多情况下可能无法运行