PAT-乙-1081 1081 检查密码 (15 分)

本文详细解析了一段用于检测密码强度的C++代码,代码通过判断密码长度、字符类型(字母、数字)以及特殊字符的存在与否,来评估密码是否过于简短、混乱或完美。通过阅读本文,读者可以了解如何使用C++实现密码安全性的基本检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

代码

#include <iostream>

using namespace std;

int main()
{
	int n;
	cin>>n;
	string s;
	getline(cin, s);
	
	for(int i=0; i<n; i++){
		getline(cin, s);
		if(s.length()<6){
			cout<<"Your password is tai duan le."<<endl;
		}
		else{
			bool flag = true;
			for(int i=0; i<s.length(); i++){
				if(!(s.at(i)>='a' && s.at(i)<='z')
				&& !(s.at(i)>='A' && s.at(i)<='Z')
				&& !(s.at(i)>='0' && s.at(i)<='9')
				&& s.at(i)!='.'){
					flag = false;
					cout<<"Your password is tai luan le."<<endl;
					break;
				}
			}
			if(flag){
				bool isDigit = false;
				bool isLetter = false;
				for(int i=0; i<s.length(); i++){
					if((s.at(i)>='a' && s.at(i)<='z')
					|| (s.at(i)>='A' && s.at(i)<='Z')){
						isLetter = true;
					}
					if(s.at(i)>='0' && s.at(i)<='9'){
						isDigit = true;
					}
				}
				if(isDigit && !isLetter){
					cout<<"Your password needs zi mu."<<endl;
				}
				else if(!isDigit && isLetter){
					cout<<"Your password needs shu zi."<<endl;
				}
				else{
					cout<<"Your password is wan mei."<<endl;
				}
			}
		}
	}	 
	
	return 0;
}

注解

1、模拟题。按题目要求来即可。

结果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值