PAT B1081 check the password (15 points)

Topic links : https://pintia.cn/problem-sets/994805260223102976/problems/994805261217153024

Title Description
This title requires 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
given input of the first line of 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
for each user's password, 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, the 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, the 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

样例输出
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.

Code

#include <iostream>
#include <string>
using namespace std;

int main() {
	string str;
	int n, len;
	cin >> n;			
	getchar();
	for(int i = 0; i < n; i++) {
		getline(cin, str);
		len = str.size();
		if(len < 6) {
			cout << "Your password is tai duan le." << endl;
			continue;
		}
		bool flag1 = false, flag2 = false, flag3 = false;
		for(int j = 0; j < len; j++) {
			char c = str[j];
			if(c >= 'A' && c <= 'Z')
				c = c - 'A' + 'a';
			if(c >= '0' && c <= '9')
				flag3 = true;
			else if(c >= 'a' && c <= 'z')
				flag2 = true;
			else if (c == '.');
			else
				flag1 = true;
		}
		if(flag1) {
			cout << "Your password is tai luan le." << endl;
		}
		else if(flag2 && !flag3)
			cout <<"Your password needs shu zi." <<endl;
		else if(flag3 && !flag2)
			cout << "Your password needs zi mu." << endl;
		else 
			cout << "Your password is wan mei." << endl;
	}
	return 0;
}
Published 327 original articles · won praise 12 · views 20000 +

Guess you like

Origin blog.csdn.net/Rhao999/article/details/105223995