当前位置: 首页 > article >正文

PAT A1035 Password

1035 Password

分数 20

作者 CHEN, Yue

单位 浙江大学

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

 

* 将密码含有 1 ,l, 0, O的字符换为对应的字符,然后输出修改后的密码;
 *
 * 修改字符可以用一个map来存储,如果有修改的密码可以用vector来存储,最后判断vector的
 * 值,根据题目要求输出相应的内容。

/**
 * 将密码含有 1 ,l, 0, O的字符换为对应的字符,然后输出修改后的密码;
 * 
 * 修改字符可以用一个map来存储,如果有修改的密码可以用vector来存储,最后判断vector的
 * 值,根据题目要求输出相应的内容。
*/

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

typedef pair<string, string> PSS;

map<char, char> mp = {{'1', '@'}, {'0', '%'}, {'l', 'L'}, {'O', 'o'}};

string modify(string word)
{
    string s;
    for(auto ele : word)
    {
        if(mp.find(ele) != mp.end())
            ele = mp[ele];
        s.push_back(ele);
    }
    
    return s;
}

int main()
{
    int n;
    cin >> n;
    
    vector<PSS> res;
    
    for(int i=0; i<n; ++i)
    {
        string name, word;
        cin >> name >> word;
        string s = modify(word);
        if(s != word)   res.push_back({name, s});
    }
    
    if(res.size() == 0)
    {
        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
    {
        cout << res.size() << endl;
        for(auto ele : res)
            cout << ele.first << ' ' << ele.second << endl;
    }
    
    return 0;
}


http://www.kler.cn/a/18100.html

相关文章:

  • 【每日刷题】Day152
  • openpyxl处理Excel模板,带格式拷贝行和数据填入
  • 设计模式学习总结(一)
  • 基于Zynq FPGA对雷龙SD NAND的性能测试评估
  • Vue 组件传递数据-Props(六)
  • 【Django】视图函数
  • 机器人控制系统学习和研究中数学的重要性
  • 数据库系列-什么是 JDBC?它的作用是什么?
  • centos7 安装python的命令
  • 【Halcon】找到设备上的 标识牌
  • Java设计模式(十八)中介者模式
  • Nacos注册中心一些配置说明
  • 《Netty》从零开始学netty源码(五十三)之PoolThreadCache的功能
  • MySQL面试八股文:索引篇
  • 我把Solon打包成了native image,速度快的惊人
  • 【linux的学习与软件安装】
  • 计算机操作系统实验:页面置换算法的实现
  • 充电桩测试设备TK4800充电桩现校仪检定装置
  • MySQL优化二索引使用
  • 信息安全从业人员职业规划(甲方乙方分别说明)
  • 中兴B860AV2.1-T(M)-高安版-当贝纯净桌面线刷固件包
  • Facebook 用户量十分庞大,为什么还使用 MySQL 数据库?
  • IDEA沉浸式编程体验
  • 锁相环技术,单边带信号,信号的调制
  • MySQL数据库之索引
  • 【SpringMVC】三、SpringMVC获取请求参数与域数据共享