hdu 2024 C语言合法标识符
Problem Description
输入一个字符串,判断其是否是C的合法标识符。
Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input
3
12ajf
fi8x_a
ff ai_2
Sample Output
no
yes
no
解:本题并不考虑关键字
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const double inf=1e20;
const int maxn=2e5+10;
const int mod=1e9+7;
char a[maxn];
int main(){
int t;
scanf("%d",&t);
getchar();
while(t--){
gets(a);
int len=strlen(a);
if((‘a‘<=a[0]&&a[0]<=‘z‘)||(‘A‘<=a[0]&&a[0]<=‘Z‘)||a[0]==‘_‘){}
else{
printf("no\n");
continue;
}
int i;
for(i=0;i<len;i++){
if(a[i]==‘_‘||(‘0‘<=a[i]&&a[i]<=‘9‘)||(‘a‘<=a[i]&&a[i]<=‘z‘)||(‘A‘<=a[i]&&a[i]<=‘Z‘)){
}else{
printf("no\n");
break;
}
}
if(i==len)printf("yes\n");
}
return 0;
}相关推荐
sillion 2020-07-09
拉斯厄尔高福 2020-11-04
嵌入式资讯精选 2020-10-15
zhaochen00 2020-10-13
penkgao 2020-10-13
wanshiyingg 2020-09-29
Mars的自语 2020-09-27
shenwenjie 2020-09-24
一个逗逗 2020-09-22
flycony 2020-09-13
zhaochen00 2020-08-20
Biao 2020-08-20
qingsongzdq 2020-08-19
penkgao 2020-08-17
cetrolchen 2020-08-14