Problem Description
輸入一個字符串,判斷其是否是C的合法標識符。
Input
輸入數據包含多個測試實例,數據的第一行是一個整數n,表示測試實例的個數,然後是n行輸入數據,每行是一個長度不超過50的字符串。
Output
對於每組輸入數據,輸出一行。如果輸入數據是C的合法標識符,則輸出"yes",否則,輸出“no”。
Sample Input
3 12ajf fi8x_a ff ai_2
Sample Output
no yes no
/*
判斷 字符串符合c變量標準
cin.getline();bool型 isdigit 、isalpha
continue用法
*/
/*
判斷 字符串符合c變量標準
cin.getline();
bool型 isdigit 、isalpha
continue用法
*/
#include <iostream>
#include <cstring>
using namespace std;
char s[51];
int main() {
int t;
cin >> t;
getchar();
while(t--) {
cin.getline(s,51);
bool flag = true;
int len = strlen(s);
if(isdigit(s[0])) {
cout << "no"<<endl;
continue;
}
for(int i = 0; i < len; i++) {
if(s[i] != '_' && isdigit(s[i]) == 0 && isalpha(s[i]) == 0) {
flag = false;
break;
}
}
if(flag) cout << "yes" << endl;
else cout << "no" << endl;
}
return 0;
}