您的位置:首页 > 其它

PAT (Basic Level) 1081 检查密码

2020-03-06 12:37 561 查看

题意

按要求校验密码。

思路

模拟即可。要使用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 ! ! !

  • 点赞
  • 收藏
  • 分享
  • 文章举报
xavier_cai 发布了107 篇原创文章 · 获赞 16 · 访问量 6190 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: