IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 数据结构与算法 -> A1035 Password (20 分)PAT甲级 (Advanced Level) Practice(C++)满分题解【字符串相关】 -> 正文阅读

[数据结构与算法]A1035 Password (20 分)PAT甲级 (Advanced Level) Practice(C++)满分题解【字符串相关】

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>
using namespace std;
vector<string> modified_User;
int main()
{
	int n;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		string name, password;
		cin>>name>>password;
		//1 (one) by @, 0 (zero) by %, l by L, and O by o
		bool modified = false;
		for (int j = 0; j < password.length(); j++)
		{
			if (password[j] == '1') {
				password[j] = '@';
				modified = true;
			}
			else if (password[j] == '0') {
				password[j] = '%';
				modified = true;
			}
			else if (password[j] == 'l') {
				password[j] = 'L';
				modified = true;
			}
			else if (password[j] == 'O') {
				password[j] = 'o';
				modified = true;
			}
		}
		if (modified) {
			string record = name + " " + password;
			modified_User.push_back(record);
		}
	}
	int size = modified_User.size();
	if (size == 0) {
		if (n == 1)
			printf("There is 1 account and no account is modified\n");
		else
			printf("There are %d accounts and no account is modified\n", n);
	}
	else {
		printf("%d\n", size);
		for (int i = 0; i < size; i++)
		{
			cout<<modified_User[i]<<endl;
		}
	}
	return 0;
}

运行结果如下:

?

  数据结构与算法 最新文章
【力扣106】 从中序与后续遍历序列构造二叉
leetcode 322 零钱兑换
哈希的应用:海量数据处理
动态规划|最短Hamilton路径
华为机试_HJ41 称砝码【中等】【menset】【
【C与数据结构】——寒假提高每日练习Day1
基础算法——堆排序
2023王道数据结构线性表--单链表课后习题部
LeetCode 之 反转链表的一部分
【题解】lintcode必刷50题<有效的括号序列
上一篇文章      下一篇文章      查看所有文章
加:2022-04-24 09:40:34  更:2022-04-24 09:43:19 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/26 8:51:26-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码