PAT甲级1035

作者: minibanana丶 | 来源:发表于2020-04-02 10:32 被阅读0次

1035 Password (20分)
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

Input Specification:
Each input file contains one test case. Each case contains a positive integer N (≤1000), followed by N lines of accounts. Each account consists of a user name and a password, both are strings of no more than 10 characters with no space.

Output Specification:
For each test case, first print the number M of accounts that have been modified, then print in the following M lines the modified accounts info, that is, the user names and the corresponding modified passwords. The accounts must be printed in the same order as they are read in. If no account is modified, print in one line There are N accounts and no account is modified where N is the total number of accounts. However, if N is one, you must print There is 1 account and no account is modified instead.

Sample Input 1:
3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

Sample Output 1:
2
Team000002 RLsp%dfa
Team000001 R@spodfa

Sample Input 2:
1
team110 abcdefg332

Sample Output 2:
There is 1 account and no account is modified

Sample Input 3:
2
team110 abcdefg222
team220 abcdefg333

Sample Output 3:
There are 2 accounts and no account is modified

#include <iostream>
using namespace std;
const int N = 1010;
string id[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;
    cin >> n;
    int m = 0;
    int a = n;
    while (n--){
        string cur_id, cur_pwd;
        cin >> cur_id >> cur_pwd;
        string changed_pwd = change(cur_pwd);
        if (changed_pwd != cur_pwd) { //如果 改变后的密码与原密码不相同,就记录一下
            id[m] = cur_id;
            pwd[m] = changed_pwd;
            m++;
        }
    }
    if (m == 0){
        if (a == 1) cout << "There is 1 account and no account is modified" << endl;
        else cout << "There are " << a << " accounts and no account is modified" << endl;
    }
    else {
        cout << m << endl;
        for (int i = 0; i < m; i++) cout << id[i] << " " << pwd[i] << endl;
    }
    return 0;
}

这题考查字符串的处理,这题不是很难,捋清思路就好了。

相关文章

  • PAT甲级1035

    1035 Password (20分)To prepare for PAT, the judge sometime...

  • PAT A1001 A+B Format (20)

    PAT A1001 A+B Format 原题链接PAT甲级题目目录(简书)PAT甲级题目目录(CSDN)在CSD...

  • 字符串输入问题

    PAT 甲级 1100 People on Mars count their numbers with base ...

  • PAT甲级题解 全部 JAVA版 持续更新

      临近过年,闲来无事。恰逢弟弟准备考PAT甲级,总是问我一些问题。又见网上PAT甲级多为c/c++版本的答案。罕...

  • PAT-B 1035. 插入与归并(25)

    传送门 https://www.patest.cn/contests/pat-b-practise/1035 题目...

  • PAT甲级 1043 Is It a Binary Search

    原题链接 PAT甲级 1043 Is It a Binary Search Tree (25 分) 题目大意 给定...

  • 2020-02-06

    PAT-甲级 做题笔记 目录 0000 做题 Tips 基本经验1003 Emergency (Dijkstra ...

  • Pat 甲级 1001

    太感人终于把1001做对了,一开始没有看清题目要求。产生各种各样的错误,最后又有编译错误。在Pat中Java的类名...

  • Pat 甲级1002

    在编译器中将边界设为1001 然后提交的代码边界设为1000,结果产生了部分正确的结果,实在是不应该,浪费太多时间...

  • PAT甲级题目

    先把会做的做了,emmmm 1006 水题,关键就是在于如何切分字符串而已,考的应该也就是字符串了: 1007 这...

网友评论

    本文标题:PAT甲级1035

    本文链接:https://www.haomeiwen.com/subject/msitphtx.html