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;
}


相关文章
|
传感器 物联网 数据处理
认识IoT的基本概念和架构
物联网(Internet of Things, IoT)是现代信息技术的重要组成部分,通过将物理设备连接到互联网,实现设备之间的互联和数据交换。随着传感技术、通信技术和数据处理能力的不断提升,物联网在各个领域展现出巨大的潜力和应用前景。本文将介绍物联网的基本概念、架构、关键技术及其应用场景,并探讨其未来的发展趋势。
3693 3
|
Android开发
Android实现语音播报的两种方式
Android实现语音播报的两种方式
1170 0
|
6月前
|
机器学习/深度学习 数据挖掘 PyTorch
PyTorch深度学习实战 |手算​​FCN全卷积神经网络
本文介绍了FCN-8s语义分割网络的实现细节。首先解释了语义分割的概念及其与图像分类的区别,重点分析了FCN网络结构中的全卷积化、上采样和跳跃连接三个关键技术。全卷积化将传统CNN的全连接层改为卷积层,实现像素级分类;上采样通过双线性插值恢复特征图尺寸;跳跃连接则融合高低层特征以提升细节表现。文章详细推导了损失函数的计算过程,并提供了完整的PyTorch实现代码,包括双线性插值权重初始化、VGG16骨干网络和FCN-8s主体结构。最后通过测试验证了模型能正确输出与输入尺寸匹配的预测结果。
509 3
|
负载均衡 安全 Cloud Native
Service Mesh:原则、挑战和演变
服务网格作为云原生架构中的关键组件,旨在解决微服务间通信的复杂性。它通过提供服务发现、负载均衡、安全控制和可观测性等功能,帮助开发者更高效地管理分布式系统。本文探讨了服务网格的起源、核心功能、在多云环境中的应用及其未来发展趋势,展示了其在现代软件架构中的重要价值。
586 10
Service Mesh:原则、挑战和演变
|
C# 图形学
【Unity3D实例-功能-拔枪】角色拔枪(一)动态创建武器
本文详细讲解了Unity射击游戏中角色拔枪功能的实现方法,包括动态创建武器、设置拔枪动画、角色手部挂载点配置及动画器逻辑搭建,完整呈现拔枪动作的制作流程。
660 4
|
11月前
|
人工智能 程序员 调度
智能体来了(西南总部):AI调度官与 AI Agent 指挥官的 Prompt 与 Workflow 实战
在大模型落地产业的浪潮中,成都AI智能体产业基地正崛起为西南AI枢纽。AI Agent指挥官作为新职业角色,通过Prompt设计、Workflow编排与多智能体协同,推动AI从“能聊天”到“会办事”的跃迁,成为企业智能化转型的核心调度者。
542 4
|
人工智能 前端开发 测试技术
告别 GUI Agent 工程基建噩梦!阶跃星辰开源 4B 模型,本地轻松部署,玩转安卓应用
阶跃星辰开源GELab-Zero,首发4B GUI Agent模型及完整基建,支持一键部署,在多端性能达SOTA。同步推出真实场景评测基准AndroidDaily,推动GUI智能体规模化落地。
1423 10
告别 GUI Agent 工程基建噩梦!阶跃星辰开源 4B 模型,本地轻松部署,玩转安卓应用
|
传感器 存储 安全
物联网技术
物联网(Internet of Things,IoT)是指通过感知设备、网络传输、数据处理等技术手段,实现物与物、人与物之间的互联互通和智能化管理的网络
2765 48
|
弹性计算 网络协议 应用服务中间件
|
IDE Java 程序员
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
2157 0
Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总