您的位置:首页 > 编程语言 > C语言/C++

HDU 2024 C语言合法标识符(笑)

2016-10-24 21:41 183 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2024


是的,这题很简单

,但是1A也不是那么容易

,为什么把这么简单的题记录在博客呢,因为提醒自己要严谨,注意细节。

分析:

这题就是合法的命名规则。规定开头不能用数字,可以用大小写字母和下划线,下划线相当于字母一样,所以________也是命名合法的。必须把整个字符串遍历完,遇到奇怪的字符除了字母和下划线数字的就要打出no,no和yes也是小写的


所以就是:

关键细节

没有什么坑的数据

关键词也不用考虑 就是小心点就行了

#include<cstdio>
#include<cstring>
#include<queue>
#include <iostream>
#include<algorithm>

using namespace std;

char str[55];
int main(){
int T;
cin>>T;
int cnt;
getchar();
while(T--){
int ans;
gets(str);
int len = strlen(str);
int flag = 0;

for(int i= 0;i<len;i++){

if(str[0]>='0'&&str[0]<='9'){
printf("no\n");
flag=1;
break;
}
else if((str[i]<='z'&&str[i]>='a')||(str[i]<='Z'&&str[i]>='A')||str[i]=='_'||(str[i]>='0'&&str[i]<='9')){
continue;
}
else{
printf("no\n");
flag = 1;
break;

}

}
if(!flag)
printf("yes\n");
}

return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: