PAT (Basic Level) Practice (Chinese) 1081 check passwords (15 points)

1. Topic

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 points . must also be both letters are also numbers .

Input formats:

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

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.

 2. Code

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	int n;
	string temp;
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++)
	{
		getline(cin, temp);
		if (temp.length() < 6) { cout << "Your password is tai duan le." << endl; continue; }
		int count = 0; bool  num = false, alpha = false;
		for (int j = 0; j < temp.length(); j++)
		{
			if (temp[j] >= '0'&&temp[j] <= '9' || temp[j] >= 'A'&&temp[j] <= 'Z' || temp[j] >= 'a'&&temp[j] <= 'z' || temp[j] == '.')
				count++;
			if (temp[j] >= '0'&&temp[j] <= '9')num = true;
			if (temp[j] >= 'A'&&temp[j] <= 'Z' || temp[j] >= 'a'&&temp[j] <= 'z')alpha = true;
		}
		if (count != temp.length()) { cout << "Your password is tai luan le." << endl; continue; }
		if(!num&&alpha) { cout << "Your password needs shu zi." << endl; continue; }
		if (num&&!alpha) { cout << "Your password needs zi mu." << endl; continue; }
		cout << "Your password is wan mei." << endl;
	}

}

 

Published 136 original articles · won praise 4 · Views 2473

Guess you like

Origin blog.csdn.net/qq_42325947/article/details/104735622