PAT A1035 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 [email protected]

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

题目大意:输入n组数据,第一个字符串为数据编号,第二个字符串为需要修改的密码。如果第二个字符串中有1就替换成@,0替换成%,l替换成L,O替换成o

如果有密码被修改,输出修改的数量已经修改过的密码的编号和修改后的密码。如果没有修改,则需要输出(注意输出的单复数!)

There is 1 account and no account is modified          或者
There are N accounts and no account is modified

解题思路:

  (1)将编号和密码用一个结构体来封装,同时包含一个是否修改的标志。

  (2)对输入的数据进行处理,遇到需要替换的就替换,并把修改标志改为true,否则的话修改标志位false。

  (3)用一个计数器记录修改的数量,初值为n,遇到一个未修改的,就将num--,最终num如果为0,说明没有元素被修改,num不为0时,输出num,并且输出修改标志位为true的数据。

#include<iostream>

using namespace std;

struct Password {
    char id[12];
    char pass[12];
    bool isChange;
}p[1001];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].id >> p[i].pass;
    }
    int num = n;//计算有多少个被修改
    for (int i = 0; i < n; i++) {
        //对密码进行修改
        for (int j = 0; j < strlen(p[i].pass);j++) {
            if (p[i].pass[j] == ‘1‘) {
                p[i].pass[j] = ‘@‘;
                p[i].isChange = true;
            }
            else if (p[i].pass[j] == ‘0‘) {
                p[i].pass[j] = ‘%‘;
                p[i].isChange = true;
            }
            else if (p[i].pass[j] == ‘l‘) {
                p[i].pass[j] = ‘L‘;
                p[i].isChange = true;
            }
            else if (p[i].pass[j] == ‘O‘) {
                p[i].pass[j] = ‘o‘;
                p[i].isChange = true;
            }
        }
        if (p[i].isChange != true) {
            //没有被修改的话,num--
            p[i].isChange = false;
            num--;
        }
    }

    if (num == 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 << num << endl;
        for (int i = 0; i < n; i++) {
            //只输出被修改的内容
            if (p[i].isChange) {
                cout << p[i].id << " " << p[i].pass << endl;
            }
        }
    }
    system("pause");
    return 0;
}

原文地址:https://www.cnblogs.com/syq816/p/12543148.html

时间: 2024-10-13 22:51:41

PAT A1035 Password的相关文章

A1035 Password (20)(20 分)

A1035 Password (20)(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 (zer

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) fro

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) fro

PAT 甲级 1035 Password

https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520 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 di

PAT甲级——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)

PAT Advanced 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)

PAT 甲级 A1035 (2019/02/10)

1 #include<cstdio> 2 #include<cstring> 3 struct user{ 4 char id[20]; 5 char password[20]; 6 bool ischange; 7 }List[1001]; 8 bool isalter(user &t, int &count){//1 (one) by @, 0 (zero) by %, l by L, and O by o 9 int len = strlen(t.passwo

PAT甲题题解-1035. Password (20)-水

题意:给n个用户名和密码,把密码中的1改为@,0改为%,l改为L,O改为o. 让你输出需要修改密码的用户名个数,以及对应的用户名和密码,按输入的顺序.如果没有用户需要修改,则输出对应的语句,注意单复数... 没啥好说的,就for一遍密码,把需要改的改下,存入到ans中去. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cm

PAT:1035. Password (20) AC

#include<stdio.h> #include<string.h> typedef struct STU { char mID[15]; char mpass[15]; bool tag; }STU; STU arr[1010]; int main() { memset(arr,0,sizeof(arr)); int n,change=0; scanf("%d",&n); for(int i=0 ; i<n ; ++i) { scanf(&q