1035.Password

题目描述

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>
#include <vector>
#include <string>
using namespace std;
struct node {
    string id, pwd;
};
int main() {
    int n;
    string id, pwd;
    scanf("%d", &n);
    vector<node> stu;
    for (int i = 0; i < n; i++) {
        cin >> id >> pwd;
        int flag = 0;
        for (int i = 0; i < pwd.length(); i++) {
            switch (pwd[i]) {
            case '1':pwd[i] = '@'; flag = 1; break;
            case '0':pwd[i] = '%'; flag = 1; break;
            case 'l':pwd[i] = 'L'; flag = 1; break;
            case 'O':pwd[i] = 'o'; flag = 1; break;
            default: break;
            }
        }
        if (flag) stu.push_back(node{ id,pwd });
    }
    int cnt = stu.size();
    if (cnt != 0) {
        printf("%d\n", cnt);
        for (int i = 0; i < cnt; i++) cout << stu[i].id << " " << stu[i].pwd << endl;
    }
    else if (n == 1) printf("There is 1 account and no account is modified");
    else printf("There are %d accounts and no account is modified", n);
    return 0;
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,150评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,436评论 0 23
  • 2019 1.18 星期五 天气晴 今天孩子放假了!漫长的假期从周一开始了! 今晚上开家长...
    往事随风_452e阅读 1,774评论 1 1
  • 以撒年老,眼睛昏花,看不见东西了;(创世记 27:1 新译本) 以撒是敬畏神的人,他身上有很多的优点:顺服...
    wakeup王阅读 5,351评论 0 0
  • 10.21先试试表达攻击性 本周主要围绕着攻击性去讲解的,而攻击性就相当于负能量一样或者一些情绪一样可能会在不自...
    徐猛_Merlin阅读 1,703评论 0 0