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


相关文章
|
算法 Unix
socket套接字选项getsockopt&setsockopt
setsockopt()函数用于任意类型、任意状态套接口的设置选项值。尽管在不同协议层上存在选项,但本函数仅定义了最高的“套接口”层次上的选项。在Unix网络编程中通常用到getsockopt和setsockopt两个函数来获取和设置套接口的选项。getsockopt()函数用于获取任意类型、任意状态套接口的选项当前值,并把结果存入optval。
316 0
|
机器学习/深度学习 数据建模 定位技术
【数据结构】图的基本概念—无/有向图、权和网、完全图、路径与回路
【数据结构】图的基本概念—无/有向图、权和网、完全图、路径与回路
6130 0
【数据结构】图的基本概念—无/有向图、权和网、完全图、路径与回路
|
缓存 监控 小程序
App性能测试揭秘(Android篇)
性能测试在移动测试领域一直是一个大难题,它最直观的表现是用户在前台使用 App 时的主观体验,然而决定体验优劣的背后,涉及到了许许多多的技术变迁。阅读此文,带你揭秘App性能测试。
5755 0
App性能测试揭秘(Android篇)
|
供应链 监控 安全
云 HIS 系统的药品库存管理功能的特性
云HIS系统在药品库存管理方面引入了实时监控、智能预警、高效采购、精确追溯等多项新特性,提升了管理效率和准确性。系统支持多终端访问,实现自动化流程,并确保合规性和数据安全,同时还可与供应链集成,优化库存结构,提供全方位的药品管理解决方案。
502 5
云 HIS 系统的药品库存管理功能的特性
|
XML Java 应用服务中间件
tomcat学习一:tomcat 目录及配置文件学习 server.xml 等
这篇文章是关于Apache Tomcat服务器的目录结构、配置文件(特别是server.xml)的详细介绍和学习指南。
765 0
tomcat学习一:tomcat 目录及配置文件学习 server.xml 等
|
算法 计算机视觉 Python
图像处理与NumPy的完美结合
【4月更文挑战第17天】NumPy在Python图像处理中扮演重要角色,它支持高效的矩阵运算,使图像表示和操作变得简单。通过NumPy,可以方便地读取、显示图像,执行算术运算和滤波操作。此外,结合傅里叶变换和直方图均衡化等高级技术,NumPy能实现复杂图像处理任务,提升对比度和分析频率特性。其灵活性和效率为图像处理领域带来便利和进步。
|
数据安全/隐私保护
BUUCTF 穿越时空的思念 1
BUUCTF 穿越时空的思念 1
482 1
|
存储 安全 前端开发
基于OIDC的SSO单点登录
基于OIDC的SSO单点登录
1433 0
|
机器学习/深度学习 人工智能 算法
解密蚂蚁研发效能:如何用数据驱动效能提升?
本文整理自蚂蚁金服解决方案架构师添棋在「中国DevOps社区杭州第3届Meetup」上的分享《研发洞察:如何用数据驱动效能提升》,将围绕决策辅助和研发辅助两个方向,详细讲解在蚂蚁金服内部如何基于AI、数据技术,洞察研发效率,提供面向一线研发和团队TL的提效解决方案
1454 0
解密蚂蚁研发效能:如何用数据驱动效能提升?
|
Android开发 开发者
Android Studio 安装APK在虚拟机时报 Installation failed due to: 'null' 解决
Android Studio 安装APK在虚拟机时报 Installation failed due to: 'null' 解决
978 0
Android Studio 安装APK在虚拟机时报 Installation failed due to: 'null' 解决