[PAT A1035]Password

[PAT A1035]Password

题目描述

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.

输入格式

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.

输出格式

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.

输入样例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

解析

  1. 题目的大概意思就是,由于有些不同字符之间会有相似的模样,很难区分,现在给我们N个用户的用户名和密码,如果他们的密码中有:
    0:那么我们用%来替换它
    1:那么我们用@来替换他
    l(小写字母l):那么我们用L来替换它
    O:那么我们用o来替换它
  2. 如果有M个人的密码被更改了,那么我们输出M,并且按次序输出M个人的用户名和密码,如果没有人的密码被更改,那么我们输出There are N accounts and no account is modified和There is N accounts and no account is modified(这种情况只存在于输入的总用户数为1)
  3. 具体代码和解析见注释:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
 vector<string> ans1; //用于存放用户名
 vector<string> ans2; //用于存放密码
 int N, num, count = 0; //这个num是我写题写到一半了发现输入的N被更改了使用的暂存的变量
 //因为懒得改了,所以大家在写的时候可以把while改成for循环,这样就不用使用这个变量了
 cin >> N;
 num = N;
 while (N--) {
  bool change = false; //这个用户有没有被更改过
  string user, password;
  cin >> user >> password;
  for (int i = 0; i < password.length(); i++) {
   if (password[i] == '1') {
    password[i] = '@';
    change = true;
   }
   if (password[i] == '0') {
    password[i] = '%';
    change = true;
   }
   if (password[i] == 'l') {
    password[i] = 'L';
    change = true;
   }
   if (password[i] == 'O') {
    password[i] = 'o';
    change = true;
   }   //以上是四种需要更改的情况
  }
  if (change) {
   count++;
   ans1.push_back(user); //如果更改了,把它们存到vector中
   ans2.push_back(password);
  }
 }
 if (!count) {
  if(num==1)  cout << "There is " << num << " account and no account is modified";
  else cout << "There are " << num << " accounts and no account is modified";
  //这里注意区分is和are单复数形式
 }
 else {
  cout << count << endl;
  for (int i = 0; i < count; i++)cout << ans1[i] << " " << ans2[i] << endl;
 }
 return 0;
}
水平有限,如果代码有任何问题或者有不明白的地方,欢迎在留言区评论;也欢迎各位提出宝贵的意见!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值