PAT (Basic Level) 1081 检查密码

本文详细介绍了如何通过C++实现密码强度的校验算法。包括密码长度检查、字符类型判断等关键步骤,确保密码既包含数字又包含字母,且长度符合要求。适合初学者理解和实践。

题意

按要求校验密码。

思路

模拟即可。要使用getline。

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	cin.ignore(1);
	for (int i = 0; i < n; ++i) {
		string s;
		getline(cin, s);
		if (s.size() < 6) {
			cout << "Your password is tai duan le.\n";
			continue;
		}
		bool legal = true, dig = false, alp = false;
		for (auto e : s) {
			auto check = [&](char c) {
				if (isdigit(c)) dig = true;
				if (isalpha(c)) alp = true;
				if (isdigit(c) || isalpha(c) || c == '.') return true;
				return false;
			};
			legal &= check(e);
		}
		if (!legal) {
			cout << "Your password is tai luan le.\n";
			continue;
		}
		if (dig && !alp) {
			cout << "Your password needs zi mu.\n";
			continue;
		}
		if (!dig && alp) {
			cout << "Your password needs shu zi.\n";
			continue;
		}
		cout << "Your password is wan mei.\n";
	}
	return 0;
} 	

HINT

不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值