zoukankan      html  css  js  c++  java
  • 1035 Password

    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 (≤), 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

    题意:

      给出一组用户的密码,按照要求替换密码中的字符。

    思路:

      模拟。

    Code:

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct User {
     6     string name;
     7     string password;
     8 };
     9 
    10 int main() {
    11     int n;
    12     cin >> n;
    13     map<char, char> mp;
    14     mp['1'] = '@';
    15     mp['0'] = '%';
    16     mp['l'] = 'L';
    17     mp['O'] = 'o';
    18     vector<User> res;
    19     for (int i = 0; i < n; ++i) {
    20         string name, password;
    21         cin >> name >> password;
    22         bool found = false;
    23         for (int j = 0; j < password.length(); ++j) {
    24             if (mp.find(password[j]) != mp.end()) {
    25                 password[j] = mp[password[j]];
    26                 found = true;
    27             }
    28         }
    29         if (found) res.push_back({name, password});
    30     }
    31     if (res.size() == 0) {
    32         if (n == 1)
    33             cout << "There is " << n << " account and no account is modified"
    34                  << endl;
    35         else
    36             cout << "There are " << n << " accounts and no account is modified"
    37                  << endl;
    38     } else {
    39         cout << res.size() << endl;
    40         for (auto it : res) cout << it.name << " " << it.password << endl;
    41     }
    42 
    43     return 0;
    44 }

    注意:

      注意第三人称单数和名词复数的使用方法。

  • 相关阅读:
    python实现简单的百度翻译
    有趣的if循环
    用python代码模拟登录网站
    解决kali中的中文乱码问题
    基于linux下的NIST数字测试(下)——测试过程
    基于linux下的NIST数字测试(上)——安装过程
    2019-2020-20199135 《网络攻防实践》第3周作业
    2019-2020-20199135 《网络攻防实践》第2周作业
    2019-2020-20199135《网络攻防实践》第1周作业
    20199135网络攻防与实践作业
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12876682.html
Copyright © 2011-2022 走看看