• pat 1035 Password(20 分)


    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 replace1 (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
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <map>
     6 #include <stack>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #define LL long long
    11 using namespace std;
    12 const int MAX = 20, MAXN = 1e3 + 10;
    13 
    14 struct node
    15 {
    16     char s1[MAX], s2[MAX];
    17 }P[MAXN];
    18 char buf1[MAX], buf2[MAX];
    19 int n, cnt = 0;
    20 map <char, char> mp;
    21 
    22 
    23 bool is_ans()
    24 {
    25     bool flag = false;
    26     int len = strlen(buf2);
    27     for (int i = 0; i < len; ++ i)
    28     {
    29         if (mp.find(buf2[i]) != mp.end())
    30         {
    31             buf2[i] = mp[buf2[i]];
    32             flag = true;
    33         }
    34     }
    35     if (flag) return true;
    36     return false;
    37 }
    38 
    39 int main()
    40 {
    41 //    freopen("Date1.txt", "r", stdin);
    42     mp['l'] = 'L', mp['O'] = 'o', mp['1'] = '@', mp['0'] = '%';
    43     scanf("%d", &n);
    44     for (int i = 1; i <= n; ++ i)
    45     {
    46         scanf("%s %s", &buf1, &buf2);
    47         if (is_ans())
    48         {
    49             strcpy(P[cnt].s1, buf1);
    50             strcpy(P[cnt ++].s2, buf2);
    51         }
    52     }
    53     if (cnt != 0)
    54     {
    55         printf("%d
    ", cnt);
    56         for (int i = 0; i < cnt; ++ i)
    57             printf("%s %s
    ", P[i].s1, P[i].s2);
    58         return 0;
    59     }
    60     if (n == 1)
    61         printf("There is 1 account and no account is modified
    ");
    62     else
    63         printf("There are %d accounts and no account is modified
    ", n);
    64     return 0;
    65 }
  • 相关阅读:
    eclipse导入源码
    servlet文件上传及下载
    MediatorPattern(中介者模式)-----Java/.Net
    IteratorPattern(迭代器模式)-----Java/.Net
    CommandPattern(命令模式)-----Java/.Net
    ResponsibilityChainPattern(责任链模式)-----Java/.Net
    TemplateMethodPattern(模板方法模式)-----Java/.Net
    InterpreterPattern(解释器模式)-----Java/.Net
    ProxyPattern(代理模式)-----Java/.Net
    FlyweightPattern(享元模式)-----Java/.Net
  • 原文地址:https://www.cnblogs.com/GetcharZp/p/9589514.html
Copyright © 2020-2023  润新知