zoukankan      html  css  js  c++  java
  • 1035 Password (20 分)

    1. 题目

    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
    

    2. 题意

    PAT考试需要生成密码,密码中一些字符往往是有歧义的,题目要求替换掉密码中有歧义的字符:1换成@0换成%l换成LO换成o。输入n个用户名和密码,对有歧义的密码进行修改,如果输入的n个密码中都没有做修改,则输出提示信息;否则,输出修改了的用户名和密码。

    3. 思路——字符串

    创建一个vector<pair<string,string>>结果数组,用于存放密码做了修改的用户名和修改后的密码,密码修改只要根据题意,将有歧义的字符替换就好了。最后根据题意如果结果数组为空,说明输入的所有密码都没有做过修改,输出相应提示信息;否则说明有密码修改过,先输出结果数组长度m,然后输出m个用户名和修改过的密码。

    4. 代码

    #include <iostream>
    #include <string>
    #include <vector>
    #include <cstdlib>
    
    using namespace std;
    
    string name, pwd;
    
    // 修改密码中有歧义的字符,如果做了修改则返回1,否则返回0 
    int isChange()
    {
    	int flag = 0;
    	for (int i = 0; i < pwd.length(); ++i)
    	{
    		switch (pwd[i])
    		{
    			case '1': pwd[i] = '@'; flag = 1; break;
    			case '0': pwd[i] = '%'; flag = 1; break;
    			case 'l': pwd[i] = 'L'; flag = 1; break;
    			case 'O': pwd[i] = 'o'; flag = 1; break;
    		}
    	}
    	return flag;
    }
    
    int main()
    {
    	int n;
    	cin >> n;
    	int cnt = 0;
    	vector<pair<string, string>> res;
    	int t = n;
    	while (t--)
    	{
    		cin >> name >> pwd;
    		// 如果密码做了修改,则加入到结果数组中 
    		if (isChange()) 
    			res.push_back(make_pair(name, pwd));
    	}
    	// 按照题目要求输出即可 
    	if (res.size() == 0)
    	{
    		if (n == 1) cout << "There is 1 account and no account is modified" << endl;
    		else cout << "There are " << n << " accounts and no account is modified" << endl;
    	} else
    	{
    		cout << res.size() << endl;
    		for (int i = 0; i < res.size(); ++i)
    			cout << res[i].first << " " << res[i].second << endl;
    	}
    	return 0;
    } 
    
  • 相关阅读:
    iOS开发基础-UITableView基本属性
    iOS开发基础-UITableView控件简单介绍
    iOS开发基础-UIScrollView实现图片缩放
    iOS开发基础-UIScrollView基础
    iOS开发基础-序列帧动画之Tom猫
    iOS开发基础-KVC简单介绍
    iOS开发基础-九宫格坐标(6)
    iOS开发基础-九宫格坐标(5)
    iOS开发基础-九宫格坐标(4)
    iOS开发基础-九宫格坐标(3)之Xib
  • 原文地址:https://www.cnblogs.com/vanishzeng/p/15479938.html
Copyright © 2011-2022 走看看