【PAT A-1035】Password

【PAT A-1035】Password

题意概述

给出 N 个账户名及其密码,要求对密码进行如下替换:

  1. @替换数字1
  2. %替换数字0
  3. 用大写字母L替换小写字母l
  4. 用小写字母o替换大写字母O

输入输出格式

输入第 1 行给出正整数 N,表示输入的账户数量。随后 N 行,每行给出一个账户名及其密码。

如果有需要修改密码的账户,第一行输出需要修改密码的数量,接下来每行输出一个账户名及其修改后的密码。若没有需要修改密码的账户,如果只输入了一个账户,输出There is 1 account and no account is modified;否则输出There are N accounts and no account is modified,N 需要用实际输入的账户数量代替。

数据规模

N ≤ 10 3 N\le {10}^3 N103

算法设计

可定义unordered_map<char,char>存储需要被替换的字母和替换字母之间的映射关系,然后遍历密码字符串进行相应替换即可。

C++代码

#include <bits/stdc++.h>
using namespace std;
using gg = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<array<string, 2>> ans;  //存储需要进行替换的账户名和密码
    unordered_map<char, char> um = {
        {'1', '@'}, {'0', '%'}, {'l', 'L'}, {'O', 'o'}};
    gg ni;
    string user, password;
    cin >> ni;
    for (gg i = 0; i < ni; ++i) {
        cin >> user >> password;
        bool f = false;  //表示该账户密码是否需要被修改
        for (auto& j : password) {
            if (um.count(j)) {
                j = um[j];
                f = true;
            }
        }
        if (f) {
            ans.push_back({user, password});
        }
    }
    if (ans.empty()) {
        ni == 1 ? (cout << "There is 1 account and no account is modified") :
                  (cout << "There are " << ni
                        << " accounts and no account is modified");
    } else {
        cout << ans.size() << "\n";
        for (auto& i : ans) {
            cout << i[0] << " " << i[1] << "\n";
        }
    }
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我真的不是cjc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值