注意
isalnum() 是数字或字母返回 非零,不是返回1
其他情况返回0
该题需注意空格问题,不是字符串中有空格,是字符串结尾有空格,所以用getline
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
int n;
cin >> n;
getchar();
for(int i=0; i<n; i++){
string a;
getline(cin,a);
if(a.length() < 6){
cout << "Your password is tai duan le." << endl;
continue;
}
int num = 0;
int let = 0;
int other = 0;
for(int j=0; j<a.length(); j++){
if(isalnum(a[j]) != 0){
if(isdigit(a[j])) num = 1;
if(isalpha(a[j])) let = 1;
}
else if(a[j] == '.') continue;
else {
other = 1;
break;
}
}
if(other == 1 || (num ==0 && let == 0))
cout << "Your password is tai luan le." << endl;
else if(num == 1 && let == 0)
cout << "Your password needs zi mu." << endl;
else if(num == 0 && let == 1)
cout << "Your password needs shu zi." << endl;
else cout << "Your password is wan mei." << endl;
}
return 0;
}