c语言合法标识符

#include <iostream>
#include <stdio.h>
using namespace std;
char str[100][51];
int main()
{
int i,j,n,f,t;

cin>>n;getchar();
for(i=1;i<=n;i++)
{
gets(str[i]);
for(j=0;str[i][j]!='\0';j++)
t=j;
f=0;
if((str[i][0]>='A'&&str[i][0]<='Z')||(str[i][0]>='a'&&str[i][0]<='z')||str[i][0]=='_')
{
f=1;
for(j=1;j<=t;j++)
{
if((str[i][j]>='0'&&str[i][j]<='9')||(str[i][j]>='A'&&str[i][j]<='Z')||(str[i][j]>='a'&&str[i][j]<='z')||str[i][j]=='_') {f=1;}
else {f=0;break;}
}
}
else f=0;
if(f==1) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}

posted @ 2015-07-19 10:26  NYNU_ACM  阅读(689)  评论(0编辑  收藏  举报