答案:
#include <stdio.h>
#include <string.h>
int main()
{char arr[60];int n = 0, i = 0, num = 0, flag;scanf("%d", &n);getchar(); //读取回车键while (n--) //循环N次{gets(arr);num = strlen(arr); //num为字符串长度flag = 1; //假设都是真if ((arr[0] >= 'a' && arr[0] <= 'z') || (arr[0] >= 'A' && arr[0] <= 'Z') || (arr[0] == '_')) //第一位如果符合c语言规定{for (i = 1; i < num; i++) //将字符串从头到尾检查{if ((arr[i] >= 'a' && arr[i] <= 'z') || (arr[i] >= 'A' && arr[i] <= 'Z')|| (arr[i] >= '0' && arr[i] <= '9') || (arr[i] == '_')) //如果符合c语言规定continue; //判断下一个字符else {flag = 0; //不符合为假break; //没必要再判断下一个字符了,直接跳出循环}}}else //第一位如果就不符合c语言规定flag = 0; //为假if (flag == 0) //如果为假printf("no\n");else //如果为真printf("yes\n");}return 0;
}