1081 检查密码 测试点2
作者:互联网
易错点
输入格式中提到:“每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串”,因此可能包含空格。测试点2即包含空格,如果用“cin>>a",测试点2会过不去,需要用cin.getline()
代码
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
bool is_legal(string s){
if(s.size()<6){
cout<<"Your password is tai duan le."<<endl;
return 0;
}
int tmp1=0;
int tmp2=0;
int tmp3;
for(int i=0;s[i]!=NULL;i++){
tmp3=0;
if(s[i]<='9'&&s[i]>='0'){
tmp1=1;
tmp3=1;
}
else if(s[i]<='z'&&s[i]>='a'){
tmp2=1;
tmp3=1;
}
else if(s[i]<='Z'&&s[i]>='A'){
tmp2=1;
tmp3=1;
}
else if(s[i]=='.'){
tmp3=1;
}
if(tmp3==0){
cout<<"Your password is tai luan le."<<endl;
return 0;
}
}
if(tmp1==0||tmp2==0){
if(tmp1==0){
cout<<"Your password needs shu zi."<<endl;
}
if(tmp2==0){
cout<<"Your password needs zi mu."<<endl;
}
return 0;
}
cout<<"Your password is wan mei."<<endl;
return 1;
}
int main()
{
int n;
string s;
cin>>n;
getchar();
for(int i=0;i<n;i++){
getline(cin,s);
is_legal(s);
}
return 0;
}
标签:测试点,1081,cin,else,密码,include,tmp3,tmp2 来源: https://www.cnblogs.com/wodeblog1982/p/16473402.html