1081 检查密码(测试点2简析)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

solution

潜在的非法字符里可能包含空格,所以不能直接用cin接收string(测试点2)

#include<iostream>
#include<string>
using namespace std;
int judge(string s){
	if(s.size() < 6) return 1;
	int num = 0, c = 0;
	for(int i = 0; i < s.size(); i++){
		if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) c = 1;
		else if(s[i] >= '0' && s[i] <= '9') num = 1;
		else if(s[i] != '.') return 2; 
	}
	if(!num) return 3;
	if(!c) return 4;
	return 5;
}
int main(){
	int n;
	string s;
	cin >> n;
	getchar();
	while(n--){
		getline(cin, s);
		if(judge(s) == 1) cout << "Your password is tai duan le." << endl;
		else if(judge(s) == 2) cout << "Your password is tai luan le." << endl;
		else if(judge(s) == 3) cout << "Your password needs shu zi." << endl;
		else if(judge(s) == 4) cout << "Your password needs zi mu." << endl;
		else cout << "Your password is wan mei." << endl;
	}
	return 0;
} 

或者

#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	string s;
	cin >> n;
	getchar();
	while(n--){
		getline(cin, s);
		if(s.size() < 6) cout << "Your password is tai duan le." << endl;
		else{
			int num = 0, c = 0, no = 0;
			for(int i = 0; i < s.size(); i++){
				if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) c = 1;
				else if(s[i] >= '0' && s[i] <= '9') num = 1;
				else if(s[i] != '.') no = 1;
			}
			if(no) cout << "Your password is tai luan le." << endl;
			else if(!num) cout << "Your password needs shu zi." << endl;
			else if(!c) cout << "Your password needs zi mu." << endl;
			else cout << "Your password is wan mei." << endl;
		}
	}
	return 0;
} 

或者
字符判断(数字&字母)

#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	string s;
	cin >> n;
	getchar();
	while(n--){
		getline(cin, s);
		if(s.size() < 6) cout << "Your password is tai duan le." << endl;
		else{
			int num = 0, c = 0, no = 0;
			for(int i = 0; i < s.size(); i++){
				if(isalpha(s[i])) c = 1;
				else if(isalnum(s[i])) num = 1;
				else if(s[i] != '.') no = 1;
			}
			if(no) cout << "Your password is tai luan le." << endl;
			else if(!num) cout << "Your password needs shu zi." << endl;
			else if(!c) cout << "Your password needs zi mu." << endl;
			else cout << "Your password is wan mei." << endl;
		}
	}
	return 0;
} 

相关推荐

  1. 数据库索引

    2024-05-04 17:08:01       58 阅读
  2. Spring Boot

    2024-05-04 17:08:01       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-04 17:08:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-04 17:08:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-04 17:08:01       87 阅读
  4. Python语言-面向对象

    2024-05-04 17:08:01       96 阅读

热门阅读

  1. P2404 自然数的拆分问题 题解

    2024-05-04 17:08:01       31 阅读
  2. android 14.0 SystemUI导航栏添加虚拟按键功能(三)

    2024-05-04 17:08:01       31 阅读
  3. 404 Not Found - GET https://registry.npmjs.org/fs-promises

    2024-05-04 17:08:01       34 阅读
  4. 大数据分析入门10分钟快速了解SQL

    2024-05-04 17:08:01       30 阅读
  5. PIXI入门系列之终章

    2024-05-04 17:08:01       35 阅读
  6. python编程功能选择建议处理方式

    2024-05-04 17:08:01       31 阅读
  7. D3CTF2024

    D3CTF2024

    2024-05-04 17:08:01      26 阅读