1081 检查密码 (15 分)
题目链接
算法分析
用两个变量ap_digit和ap_zm来记录是否有数字和字母出现,然后进行特判并输出就好了.
测试点
测试点2是在考察是否有考虑字符串中含有空格
代码实现
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
int n;
scanf("%d", &n);
getline(cin, s);
for(int i = 1; i <= n; ++ i){
getline(cin, s);
int len = s.size();
if(len < 6){
puts("Your password is tai duan le.");
continue;
}
int ap_digit = 0, ap_zm = 0;
for(int j = 0; j < len; ++ j){
if(isdigit(s[j])) ap_digit = 1;
else if(islower(s[j]) || isupper(s[j])) ap_zm = 1;
else if(s[j] == '.') continue;
else{
ap_digit = ap_zm = 0;
break;
}
}
if(ap_digit && ap_zm) puts("Your password is wan mei.");
else if(ap_digit && !ap_zm) puts("Your password needs zi mu.");
else if(!ap_digit && ap_zm) puts("Your password needs shu zi.");
else puts("Your password is tai luan le.");
}
return 0;
}