#include <iostream>
#include <cstring>
#include <stdio.h>
#include <ctype.h>
using namespace std;
int main()
{
int repeat;
cin>>repeat;
getchar();
while(repeat--)
{
char a[100];
bool flag=true;
gets(a);
int len=strlen(a);
for(int i=0;i<len;++i)
{
if(isdigit(a[0]))
{
flag=false;
break;
}
else if(!(isalnum(a[i]))&&a[i]!='_')
{
flag=false;
break;
}
}
if(flag)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}
tips:其实参考了很多人的代码。
1、cin>>repeat;之后记得加getchar()吃掉换行符。
2、学会了用gets(a)来输入一行字符串。
3、用strlen来得到字符串长度,然后用来结束对字符串的处理。
4、用isdigit()来判断数字,用isalnum()判断是否是字母或数字。记得 包含头文件ctype.h