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;
}
是的,这题很简单
,但是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;
}
相关文章推荐
- HDU 2024 - C语言合法标识符
- HDU 2024 C语言合法标识符
- hdu 2024 C语言合法标识符
- HDU——2024 —— C语言合法标识符
- Hdu 2024 C语言合法标识符
- HDU 2024 C语言合法标识符
- hdu 2024 C语言合法标识符
- hdu 2024 C语言合法标识符(ctype.h 库函数)(备战LQB)
- hdu_2024_C语言合法标识符
- hdu 2024 C语言合法标识符
- HDU_2024 C语言合法标识符
- HDU 2024 C语言合法标识符
- HDU-2024c语言合法标识符
- [hdu 2024] C语言合法标识符
- 【早起一水】 HDU 2024 C语言合法标识符
- hdu 2024 C语言合法标识符
- hdu 2024 C语言合法标识符
- HDU_2024——判断字符串是否是c语言合法标识符
- HDU 2024 -- C语言合法标识符
- HDU_2024C语言合法标识符