首页 > 其他分享 >PAT Advanced 1035 Password(20)

PAT Advanced 1035 Password(20)

时间:2022-08-21 00:44:30浏览次数:70  
标签:account PAT cur res modified accounts 20 Password psw

题目描述:

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

算法描述:模拟

题目大意:

输入整数n以及n个字符串密码
将密码中的'1'替换为'@','0'替换为'%','l'替换为'L','O'替换为'o'
输出需要替换的字符串数量及替换后的字符串

#include<iostream>
using namespace std;
const int N = 1010;
string id[N] , psw[N];

string changed(string str)
{
    string res;
    for(int i = 0 ; i < str.size() ; i++)
        if(str[i] == '0')    res += '%';
        else if(str[i] == 'O')   res += 'o';
        else if(str[i] == '1')   res += '@';
        else if(str[i] == 'l')   res += 'L';
        else    res += str[i] ;
    return res;
}

int main()
{
    int n, ans = 0;
    cin >> n ;
    for(int i = 0 ; i < n ; i++)
    {
        string cur_id,cur_psw;
        cin >> cur_id >> cur_psw ;
        string changed_psw = changed(cur_psw);
        if(changed_psw != cur_psw)
        {
            id[ans] = cur_id ;
            psw[ans] = changed_psw ;
            ans ++;
        }
    }
    if(ans){
        cout << ans << endl;
        for(int i = 0 ; i < m ; i++)
            cout << id[i] << " " << psw[i] << endl;
    }else{
        if(n == 1)
            cout<<"There is 1 account and no account is modified";
        else
            printf("There are %d accounts and no account is modified",n);
    }
    return 0;
}

标签:account,PAT,cur,res,modified,accounts,20,Password,psw
From: https://www.cnblogs.com/yztozju/p/16609174.html

相关文章

  • PAT Advanced 1027 Colors in Mars(20)
    题目描述:PeopleinMarsrepresentthecolorsintheircomputersinasimilarwayastheEarthpeople.Thatis,acolorisrepresentedbya6-digitnumber,wher......
  • 2022.8.20 线程通信问题与线程池
    7、线程通信问题生产者消费者模式的问题应用场景︰生产者和消费者问题假设仓库中只能存放一件产品,生产者将生产出来的产品放入仓库﹐消费者将仓库中产品取走消费﹒如果仓......
  • 2022.8.20 线程状态
    5、线程状态1.线程五大状态: 2.线程方法2.1停止线程案例packagecom.xing.demo03;/***测试stop*1.建议线程正常停止-->利用次数,不建议死循环*2.建......
  • 2022.8.20 线程同步
    6、线程同步1.介绍多个线程操作同一个资源     由于同一进程的多个线程共享同一块存储空间,在带来方便的同时,也带来了访问冲突问题,为了保证数据在方法中......
  • 《GB27898.4-2011》PDF下载
    《GB27898.4-2011固定消防给水设备第4部分:消防气体顶压给水设备》PDF下载《GB27898.4-2011》简介GB27898的本部分规定了消防气体顶压给水设备的术语和定义、分类、要......
  • 《GB27898.2-2011》PDF下载
    《GB27898.2-2011固定消防给水设备第2部分:消防自动恒压给水设备》PDF下载《GB27898.2-2011》简介GB27898的本部分规定了消防自动恒压给水设备的术语和定义、分类、要......
  • 2022.8.20 线程简介与三种创建方式
    1、线程简介1.多任务   现实中太多这样同时做多件事情的例子了,看起来是多个任务都在做,其实本质上我们的大脑在同一时间依旧只做了一件事情。2.多线程   ......
  • 2022.8.20 Lamda表达式与静态代理
    3、Lamda表达式λ希腊字母表中排序第十一位的字母,英语名称为Lambda避免匿名内部类定义过多其实质属于函数式编程的概念去掉了一堆没有意义的代码,只留下核心......
  • 《GB27898.3-2011》PDF下载
    《GB27898.3-2011固定消防给水设备第3部分:消防增压稳压给水设备》PDF下载《GB27898.3-2011》简介GB27898的本部分规定了消防增压稳压给水设备的术语和定义、分类、要......
  • 《GB27898.1-2011》PDF下载
    《GB27898.1-2011固定消防给水设备第1部分:消防气压给水设备》PDF下载《GB27898.1-2011》简介GB27898的本部分规定了消防气压给水设备的术语和定义、分类、要求、试验......