#include<stdio.h>
int main()
{
int n=0,i=0,m=0,flag=0;
char str[100],c;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%[^\t]",str);
if(str[0]>='A'&&str[0]<='Z'||str[0]>='a'&&str[0]<='z'||str[0]=='_')
{
for(m=0;(c=str[m]!='\0');m++)
{
if((c=str[m])>='A'&&(c=str[m])<='Z'||(c=str[m])>='a'&&(c=str[m])<='z'||(c=str[m])=='_'||(c=str[m])>='0'&&(c=str[m])<='9')
flag=0;
else
{
flag=1;
break;
}
}
if(flag==0)
printf("Great\n");
else
printf("Bad\n");
}
else
printf("Bad\n");
}
}
return 0;
}
为什么我输入第一个标识符后按回车没反应啊?(这是个判断标识符的问题)
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- CSDN专家-link 2021-11-04 11:42关注
scanf("%[^\t]",str);改为scanf("%[^\n]",str);
while循环内加一个getchar()接收掉输入n的换行符#include<stdio.h> int main() { int n=0,i=0,m=0,flag=0; char str[100],c; while(scanf("%d",&n)!=EOF) { getchar(); for(i=1;i<=n;i++) { scanf("%[^\n]",str); if(str[0]>='A'&&str[0]<='Z'||str[0]>='a'&&str[0]<='z'||str[0]=='_') { for(m=0;(c=str[m]!='\0');m++) { if((c=str[m])>='A'&&(c=str[m])<='Z'||(c=str[m])>='a'&&(c=str[m])<='z'||(c=str[m])=='_'||(c=str[m])>='0'&&(c=str[m])<='9') flag=0; else { flag=1; break; } } if(flag==0) printf("Great\n"); else printf("Bad\n"); } else printf("Bad\n"); } } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥65 永磁型步进电机PID算法
- ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
- ¥88 找成都本地经验丰富懂小程序开发的技术大咖
- ¥15 如何处理复杂数据表格的除法运算
- ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
- ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
- ¥200 uniapp长期运行卡死问题解决
- ¥15 latex怎么处理论文引理引用参考文献
- ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
- ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?