[PAT A1035]Password

解决PAT竞赛中因相似字符导致的密码混淆问题,通过将容易混淆的字符如1、0、l、O替换为@、%、L、o,确保密码的清晰性和唯一性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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;
}
水平有限,如果代码有任何问题或者有不明白的地方,欢迎在留言区评论;也欢迎各位提出宝贵的意见!
电动汽车数据集:2025年3K+记录 真实电动汽车数据:特斯拉、宝马、日产车型,含2025年电池规格和销售数据 关于数据集 电动汽车数据集 这个合成数据集包含许多品牌和年份的电动汽车和插电式车型的记录,捕捉技术规格、性能、定价、制造来源、销售和安全相关属性。每一行代表由vehicle_ID标识的唯一车辆列表。 关键特性 覆盖范围:全球制造商和车型组合,包括纯电动汽车和插电式混合动力汽车。 范围:电池化学成分、容量、续航里程、充电标准和速度、价格、产地、自主水平、排放、安全等级、销售和保修。 时间跨度:模型跨度多年(包括传统和即将推出的)。 数据质量说明: 某些行可能缺少某些字段(空白)。 几个分类字段包含不同的、特定于供应商的值(例如,Charging_Type、Battery_Type)。 各列中的单位混合在一起;注意kWh、km、hr、USD、g/km和额定值。 列 列类型描述示例 Vehicle_ID整数每个车辆记录的唯一标识符。1 制造商分类汽车品牌或OEM。特斯拉 型号类别特定型号名称/变体。型号Y 与记录关联的年份整数模型。2024 电池_类型分类使用的电池化学/技术。磷酸铁锂 Battery_Capacity_kWh浮充电池标称容量,单位为千瓦时。75.0 Range_km整数表示充满电后的行驶里程(公里)。505 充电类型主要充电接口或功能。CCS、NACS、CHAdeMO、DCFC、V2G、V2H、V2L Charge_Time_hr浮动充电的大致时间(小时),上下文因充电方法而异。7.5 价格_USD浮动参考车辆价格(美元).85000.00 颜色类别主要外观颜色或饰面。午夜黑 制造国_制造类别车辆制造/组装的国家。美国 Autonomous_Level浮点自动化能力级别(例如0-5),可能包括子级别的小
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值