PAT Basic 1081 check passwords (15 points)

This question asks you to help a site's user registration module to write a password to check the legality of small features. The site requires users to set a password must consist of not less than six characters, and can only letters, numbers and decimal point  ., both letters must also have numbers.

Input formats:

The first input line is given a positive integer N ( ≤ 100), followed by N rows, each row is given a password set by the user, not more than 80 non-empty string of characters, to enter the end.

Output formats:

Password for each user, in a row feedback information output system, the following five points:

  • If the password is legitimate, output Your password is wan mei.;
  • If the password is too short, whether legitimate or not, output Your password is tai duan le.;
  • If the password length legitimate, but there is no legal character, the output Your password is tai luan le.;
  • If the password length legitimate, but only letter not a number, output Your password needs shu zi.;
  • If the password length legitimate, but only numbers not letters, the output Your password needs zi mu..

Sample input:

5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6

Sample output:

Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.




#include <iostream>
using namespace std;
bool containAl(string s){
    for(int i=0;i<s.length();i++){
        if((s[i]>='a'&&s[i]<='z')||((s[i]>='A'&&s[i]<='Z'))) return true;
    }
    return false;
}
bool containNum(string s){
    for(int i=0;i<s.length();i++){
        if(s[i]>='0'&&s[i]<='9') return true;
    }
    return false;
}

bool isLegal(string s){
    for(int i=0;i<s.length();i++){
        if(!((s[i]>='A'&&s[i]<='Z')||(s[i]>='a'&&s[i]<=''of)||(s[i]>='0'&&s[i]<='9')||s[i]=='.')) return false;
    }
    return true;
}
void check(string s){
    if(s.length()<6) cout<<"Your password is tai duan le."<<endl;
    else if(!isLegal(s)) cout<<"Your password is tai luan le."<<endl;
    else if(!containNum(s)) cout<<"Your password needs shu zi."<<endl;
    else if(!containAl(s)) cout<<"Your password needs zi mu."<<endl;
    else cout<<"Your password is wan mei."<<endl;
}
int main(){
    int N;string s;
    cin>>N;
    getline(cin,s);
    while(N--){
        getline(cin,s);
        check(s);
    }
    system("pause");
    return 0;
}

Note the space, use getline

Guess you like

Origin www.cnblogs.com/littlepage/p/11361511.html