PAT甲级真题1035

简介: PAT甲级真题1035

PAT甲级真题1035

为了准备 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

解题思路

  • 照部就班的按照题目意思来写即可
  • 注意没有修改密码时的单复数输出
解法一
#include<iostream>
#include<vector>
using namespace std;
vector<pair<string,string>> start;//存储初始用户名、密码
vector<pair<string,string>> final;//存储出现变动的用户名、密码
int n;
string change(string str)
{
    string res;
    for (auto c : str)
    {
        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()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        string name,psw;
        cin>>name>>psw;
        start.push_back({name,psw});
    }
    string temp;
    for(auto c:start) 
    {
        temp=change(c.second);
        if(temp!=c.second)
        final.push_back({c.first,temp});
    }
    int s_len=start.size(),f_len=final.size();
    if(f_len!=0) printf("%d\n",f_len);
    if(s_len==1&&f_len==0) printf("There is 1 account and no account is modified");
    else if(s_len>1&&f_len==0) printf("There are %d accounts and no account is modified",s_len);
    else for(auto c:final) cout<<c.first<<" "<<c.second<<endl;
    return 0;
}
解法二
#include <iostream>
using namespace std;
const int N = 1010;
string name[N], pwd[N];
string change(string str)
{
    string res;
    for (auto c : str)
        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;
    scanf("%d",&n);
    int m = 0;
    for (int i = 0; i < n; i ++ )
    {
        string cur_name, cur_pwd;
        cin >> cur_name >> cur_pwd;
        string changed_pwd = change(cur_pwd);
        if (changed_pwd != cur_pwd)
        {
            name[m] = cur_name;
            pwd[m] = changed_pwd;
            m ++ ;
        }
    }
    if (!m) 
    {
        if (n == 1) puts("There is 1 account and no account is modified");
        else printf("There are %d accounts and no account is modified\n", n);
    }
    else
    {
        printf("%d\n",m);
        for (int i = 0; i < m; i ++ ) cout << name[i] << ' ' << pwd[i] << endl;
    }
    return 0;
}
解法三
#include<iostream>
#include<vector>
using namespace std;
int n, m;
int main()
{
    scanf("%d",&n);
    vector<string> p;
    string no = "There is 1 account and no account is modified";
    string no1 = "There are ", no2 = " accounts and no account is modified";
    for(int i = 1; i <= n; i ++)
    {
        string a, b;
        bool out = false;
        cin >> a >> b;
        for(auto & x : b) 
            if(x == '1') x = '@', out = true; 
            else if(x == '0') x = '%', out = true;
            else if(x == 'l') x = 'L', out = true;
            else if(x == 'O') x = 'o', out = true;
        if(out) p.push_back(a + " " + b + "\n");
    }
    if(!p.size())
    {
        if(n == 1) cout << no;
        else cout << no1 << n << no2;
    }
    else 
    {
        cout << p.size() << endl;
        for(auto x : p) cout << x;
    }
    return 0;
}


相关文章
|
6天前
|
人工智能 算法
第十三届蓝桥杯真题解析
第十三届蓝桥杯真题解析
32 3
|
6天前
|
存储 容器
PAT甲级真题1036
PAT甲级真题1036
24 1
|
6天前
PAT甲级真题1061:约会
PAT甲级真题1061:约会
21 0
|
9月前
|
测试技术 C++ Python
【浙江大学PAT真题练习乙级】1009 说反话 (20分)真题解析
【浙江大学PAT真题练习乙级】1009 说反话 (20分)真题解析
|
10月前
|
存储 人工智能 算法
【2021年蓝桥省赛真题】赛前最后冲刺,省一我来啦
【2021年蓝桥省赛真题】赛前最后冲刺,省一我来啦
259 0
|
异构计算
【数字设计】经纬恒润_2023届_笔试面试题目分享
【数字设计】经纬恒润_2023届_笔试面试题目分享
【数字设计】经纬恒润_2023届_笔试面试题目分享
|
前端开发 芯片
【数字设计】哲库科技_2023届_笔试面试题目分享
【数字设计】哲库科技_2023届_笔试面试题目分享
【数字设计】哲库科技_2023届_笔试面试题目分享
【数字设计】星宸科技_笔试面试题目分享
【数字设计】星宸科技_笔试面试题目分享
【数字设计】星宸科技_笔试面试题目分享
|
前端开发 数据格式 Python
【数字设计】壁仞科技_笔试面试题目分享
【数字设计】壁仞科技_笔试面试题目分享
【数字设计】壁仞科技_笔试面试题目分享
|
芯片 内存技术
【数字设计】乐鑫科技_笔试面试题目分享
【数字设计】乐鑫科技_笔试面试题目分享
【数字设计】乐鑫科技_笔试面试题目分享