PAT A1035 Password

题意

为了准备 PAT,系统不得不为用户生成随机密码。

但是有时一些数字和字母之间总是难以区分,比如 1(数字一)和 l(L 的小写),0(数字零)和 O(o 的大写)。

一种解决办法是将 1(数字一)替换为 @,将 0(数字零)替换为 %,将 l(L 的小写)替换为 L,将 O(o 的大写)替换为 o。

现在,你的任务就是帮助系统检查这些用户的密码,并对难以区分的部分加以修改。

输入格式

第一行包含一个整数 N,表示用户数量。

接下来 N 行,每行包含一个用户名和一个密码,都是长度不超过 10 且不含空格的字符串。

输出格式

首先输出一个整数 M,表示已修改的用户密码数量。

接下来 M 行,每行输出一个用户名称和其修改后的密码。

用户的输出顺序和读入顺序必须相同。

如果没有用户的密码被修改,则输出 There are N accounts and no account is modified,其中 N 是用户总数。

如果 N=1,则应该输出 There is 1 account and no account is modified。

数据范围

1≤N≤1000

输入样例1:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

输出样例1:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

输入样例2:

1
team110 abcdefg332

输出样例2:

There is 1 account and no account is modified

输入样例3:

2
team110 abcdefg222
team220 abcdefg333

输出样例3:

There are 2 accounts and no account is modified

思路

可以写一个change函数,将每一个密码都change一下,如果前后密码不一致,则计数++,并记录下当前的name和pwd。最后根据计数的不同输出不同的结果。

AC代码

#include <bits/stdc++.h>

using namespace std;
const int N = 1010;
string name[N],pwd[N];
int m;

string change(string a)
{
    string res = "";
    for(auto c : a)
    {
        if(c == '1')    res += '@';
        else if(c == '0')    res += '%';
        else if(c == 'l')    res += 'L';
        else if(c == 'O')    res += 'o';
        else res += c;
    }
    return res;
}

int main()
{
    int n;
    cin >> n;
    string id,cur_pwd;
    for(int i = 0;i < n;i ++)
    {
        cin >> id >> cur_pwd;
        string n_pwd = change(cur_pwd);
        if(n_pwd != cur_pwd)
        {
            name[m] = id;
            pwd[m] = n_pwd;
            m ++;
        }
    }
    if(m == 0 && n == 1)
    {
        printf("There is %d account and no account is modified",n);
    }
    else if(m == 0 && n > 1)
    {
        printf("There are %d accounts and no account is modified",n);
    }
    else
    {
        cout << m << endl;
        for(int i = 0;i < m;i ++)   cout << name[i] << ' ' << pwd[i] << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值