[1081]. Check Password (15)

topic:

[1081]. Check Password (15)

Time limit 400 ms Memory limit 65536 kB Code length limit 8000 B-judgment program Standard by CHEN, Yue

This question requires you to help the user registration module of a website write a small function for checking the validity of passwords. The website requires that the password set by the user must consist of no less than 6 characters, and can only contain English letters, numbers and decimal points ".", and must also have both letters and numbers.
Input format:
The first line of input gives a positive integer N (<=100), followed by N lines, each line gives a password set by the user, which is a non-empty string of no more than 80 characters , and ends with a carriage return.
Output format:
For each user's password, output the system feedback information in one line, divided into the following five types:
if the password is valid, output "Your password is wan mei.";
if the password is too short, output "Your password is wan mei." Your password is tai duan le.";
if the password length is legal, but there are illegal characters, output "Your password is tai luan le.";
If the password length is legal, but only letters and no numbers, output "Your password needs shu zi.";
if the password length is legal, but only numbers without letters, output "Your password needs zi mu.".
Input example:
5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
Output example:
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.

Ideas:

I use three scalars to mark, one is flag to indicate whether there are other illegal characters, flagz is used to mark whether there are letters, and flags is used to mark whether there are numbers. Of course, first check whether the length is qualified;

Notice:

The title says it is a non-empty string, but it doesn't say there is no space, so the input here should use getline. It took me two seconds to respond if the language is not good, hey;

The C++ code is as follows:

#include"iostream"
#include"cstdio"
using namespace std;
int main()
{
    int n;
    cin>>n;
    getchar();
    int i,j;
    string s1;
    for(i=0;i<n;i++)
    {
        getline(cin,s1);
        if(s1.size()<6)
        {
            cout<<"Your password is tai duan le."<<endl;
            continue;
        }
        else
        {
            int flag=0;
            int flags=0;
            int flagz=0;
            for(j=0;j<s1.size();j++)
            {
                if(s1[j]>='0'&&s1[j]<='9')
                {
                    flags=1;
                }
                else if(s1[j]>='a'&&s1[j]<='z'||s1[j]>='A'&&s1[j]<='Z')
                {
                    flagz=1;
                }
                else if(!((s1[j]>='0'&&s1[j]<='9')||(s1[j]>='a'&&s1[j]<='z'||s1[j]>='A'&&s1[j]<='Z')||s1[j]=='.'))
                {
                    flag=1;
                }
            }

            if(flag==0)
            {
                if(flags==1&&flagz==1)
                {
                    cout<<"Your password is wan mei."<<endl;

                }
                else if(flags==0&&flagz==1)
                {
                    cout<<"Your password needs shu zi."<<endl;
                }
                else if(flags==1&&flagz==0)
                {
                    cout<<"Your password needs zi mu."<<endl;
                }
            }
            else 
            {
                cout<<"Your password is tai luan le."<<endl;
            }
        }
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341422&siteId=291194637