我的个人网站 Cheese的个人主页http://www.cheese.ren/
博客来源 PAT 乙级 1081 检查密码-Cheese的个人博客http://blog.cheese.ren/101
欢迎交换友链 :-)
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
getchar();
while (n--) {
string password;
getline(cin, password);
// Password is short?
if (password.length() < 6) {
printf("Your password is tai duan le.\n");
continue;
}
// Password's length is right
// Does password have the invalid char?
bool is_right=true;
for (int i=0; i<password.length(); i++) {
if (password[i] == '.' || (password[i] >= '0' && password[i] <= '9') || (password[i] >= 'A' && password[i] <= 'Z') || (password[i] >= 'a' && password[i] <= 'z')) {
}
else {
printf("Your password is tai luan le.\n");
is_right = false;
break;
}
}
if (!is_right)
continue;
// Does password have only letter or number?
bool have_letter=false, have_number=false;
for (int i=0; i<password.length(); i++) {
if (password[i] >= '0' && password[i] <= '9')
have_number = true;
else if (password[i] >= 'A' && password[i] <= 'Z' || password[i] >= 'a' && password[i] <= 'z')
have_letter = true;
}
if (have_letter && have_number)
printf("Your password is wan mei.\n");
else {
if (have_letter)
printf("Your password needs shu zi.\n");
else if (have_number)
printf("Your password needs zi mu.\n");
}
}
return 0;
}