杭电acm2024
第31行的getchar();如果写了就是WA,不写就是AC。
但是第九行的getchar();一定要写。
函数gets的原型为:char*gets(char*buffer);
在 stdio.h中定义,如果要程序中用到此函数需包含#include<stdio.h>
gets()函数用来从标准输入设备(键盘)读取字符串直至接受到换行符或EOF时停止结束,并将读取的结果存放在buffer指针所指向的字符数组中,但换行符会被丢弃,然后在末尾添加'\0'字符。
The line consists of all characters up to and including the first newline character ('\n'). gets then
replaces the newline character with a null character ('\0') before returning the line. In contrast, the fgets function retains the newline character. _getws is
a wide-character version of gets; its argument and return value are wide-character strings.
-----from msdn
#include <stdio.h> #include <ctype.h> int main() { int n, i, flag; char s[50], c; while(~scanf("%d", &n)) { getchar(); while(n--) { gets(s); if(s[0]!='_' && !isalpha(s[0])) { printf("no\n"); continue; } flag = 0; for(i=0; s[i]!='\0'; i++) { if(!isalpha(s[i]) && !isalnum(s[i]) && s[i]!='_') { flag = 1; break; } } if(flag) printf("no\n"); else printf("yes\n"); // getchar(); } } return 0; }