1164: 零起点学算法71——C语言合法标识符(存在问题)
1164: 零起点学算法71——C语言合法标识符
Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lld
Submitted: 1080 Accepted: 484
[Submit][Status][Web Board]
Description
输入一个字符串,判断其是否是C的合法标识符。
Input
输入数据包含多个测试实例,数据的第一行是一个整数n,表示测试实例的个数,然后是n行输入数据,每行是一个长度不超过50的字符串。
Output
对于每组输入数据,输出一行。如果输入数据是C的合法标识符,则输出"yes",否则,输出“no”。
Sample Input 
3
12ajf
fi8x_a
ff ai_2
Sample Output
no
yes
no
HINT
请注意编译器的差异,可以使用TEST功能获得帮助。
Source
#include<stdio.h>
#include<ctype.h>
int main(){
int n;
char a[];
scanf("%d%*c",&n);
while(n--){
int d=;
gets(a);
if(a[]!='_'&& !isalpha(a[])){
printf("no\n");
}
else{
for(int j=;a[j]!='\0';j++){
if(a[j]!='_'&&!isalnum(a[j])){ printf("no\n");
break;
}
else{
printf("yes\n");
break;
}
}
}
}
return ;
}
//按理来说,跳出第一层循环后不会输出yes 为什么会有这种情况

AC代码:
#include<stdio.h>
#include<ctype.h>
int main(){
int n;
char a[];
while(scanf("%d%*c",&n)!=EOF){
while(n--){
int d=;
gets(a);
if(a[]!='_'&& !isalpha(a[])){
printf("no\n");
}
else{
for(int j=;a[j]!='\0';j++){
if(a[j]!='_'&&!isalnum(a[j])){ d=;
break;
}
}
puts(d ? "yes" : "no");
}
}
}
return ;
}
1164: 零起点学算法71——C语言合法标识符(存在问题)的更多相关文章
- Problem J: 零起点学算法105——C语言合法标识符
#include<stdio.h> #include<ctype.h>//调用isalpha函数 int main() { int n; ]; while(scanf(&quo ...
- 1163: 零起点学算法70——Yes,I can!
1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1147: 零起点学算法54——Fibonacc
1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 20 ...
- 1145: 零起点学算法52——数组中删数II
1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 293 ...
- 1137: 零起点学算法44——多组测试数据输出II
1137: 零起点学算法44--多组测试数据输出II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1136: 零起点学算法43——多组测试数据输出I
1136: 零起点学算法43--多组测试数据输出I Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: ...
- 1135: 零起点学算法42——多组测试数据(求和)IV
1135: 零起点学算法42--多组测试数据(求和)IV Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted ...
- 1134: 零起点学算法41——多组测试数据(a+b)III
1134: 零起点学算法41--多组测试数据(a+b)III Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitt ...
- 1133: 零起点学算法40——多组测试数据(a+b)II
1133: 零起点学算法40--多组测试数据(a+b)II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitte ...
随机推荐
- DOM操作表格——HTML DOM
html创建表格: <table berder='1' width='300'> <thead> <tr> <th>姓名</th> < ...
- linux下redis 集群配置
redis.conf 配置文件说明 daemonize no --是否把redis-server启动在后台,默认是“否”.若改成yes pidfile /var/run/redis.pid --当Re ...
- Smarty模板的基础
对前后端进行分离 如果要用的话,要从网上把smarty文件下载下来,才能用 smarty的核心是一个类 建一个php文件,写一个类文件 <?php class smarty { public $ ...
- postman传json串,以及postman官方文档
最近在调试接口遇到一个问题.就是post接口传的body是一个json串. 刚开始还不知道,百度了一下才知道,其实很简单,就是在raw里面选择json.我的天如此简单的内容,而且支持html. 于是读 ...
- MyBatis的类型自定义映射
背景 利用MyBatis将数据库的时间类型映射成Java8的时间类型,引申对不同类型的自定义映射 实现方法 1.实现MyBatis中TypeHandler接口 @MappedTypes(value = ...
- String类的indexOf方法的用法和举例
2017年3月3号博主第一次去郑州互联网公司面试,背景是这样的我先前去了农大龙子湖校园招聘投简历,然后第二天去面试了那经历可以说是很失败的一次面试,当然这跟自己的水平有关了接下来重点讲一下面试的题目: ...
- 算法模板——splay区间反转 2
实现功能:同splay区间反转 1(基于BZOJ3223 文艺平衡树) 这次改用了一个全新的模板(HansBug:琢磨了我大半天啊有木有),大大简化了程序,同时对于splay的功能也有所完善 这里面没 ...
- PHP-day01
<!--php嵌入HTML--><html><head> <title>day01</title></head><body ...
- java aes encrypt
本次使用aes 对称加密算法. 选用aes的原因是,可以还原加密串. 程序如下: public static String encode(String content){ KeyGenerator k ...
- Azure Messaging-ServiceBus Messaging消息队列技术系列5-重复消息:at-least-once at-most-once
上篇博客中,我们用实际的业务场景和代码示例了Azure Messaging-ServiceBus Messaging对复杂对象消息的支持和消息的持久化: Azure Messaging-Service ...