1035Password (20)

本文介绍了一个程序,用于检查和修改容易混淆的用户密码,如将1替换为@、0替换为%等,以提高密码的独特性和可区分性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述

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.

 

输入描述:

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.


 

输出描述:

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.

 

输入例子:

3
Team000002 Rlsp0dfa
Team000003 perfectpwd
Team000001 R1spOdfa

 

输出例子:

2
Team000002 RLsp%dfa
Team000001 R@spodfa

 

 

#include <iostream>
#include <string>
using namespace std;
struct info {
    string user;
    string pass;
};
int main() {
    int M, N = 0;    //M为输入个数,N为输出个数
    cin >> M;
    info inf[M];
    int x[M];        //记录输入中有哪几个需要修改的
    for (int i = 0; i < M; i++)
        cin >> inf[i].user >> inf[i].pass;
    for (int i = 0; i < M; i++) {
        unsigned long loc1[10] = {};  //检测1
        unsigned long loc2[10] = {};  //检测0
        unsigned long loc3[10] = {};  //检测l
        unsigned long loc4[10] = {};  //检测O
        unsigned long flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;   //用于记录检测的位置
        while (flag1 != 10) {         //记录有有多少个1,并且保存位置
            unsigned long temp = inf[i].pass.find("1", flag1);
            if (temp == -1)
                break;
            loc1[temp] = 1;
            flag1 = temp + 1;
        }
        while (flag2 != 10) {
            unsigned long temp = inf[i].pass.find("0", flag2);
            if (temp == -1)
                break;
            loc2[temp] = 1;
            flag2 = temp + 1;
        }
        while (flag3 != 10) {
            unsigned long temp = inf[i].pass.find("l", flag3);
            if (temp == -1)
                break;
            loc3[temp] = 1;
            flag3 = temp + 1;
        }
        while (flag4 != 10) {
            unsigned long temp = inf[i].pass.find("O", flag4);
            if (temp == -1)
                break;
            loc4[temp] = 1;
            flag4 = temp + 1;
        }
        if (flag1 != 0 || flag2 != 0 || flag3 != 0 || flag4 != 0) {    //若有标记,则说明需要修改,记录N的个数
            N++;
            x[i] = 1;
        }
        for (int j = 0; j < 10; j++)             //逐个修改
            if (loc1[j] != 0)
                inf[i].pass.replace(j, 1, "@");
        for (int j = 0; j < 10; j++)
            if (loc2[j] != 0)
                inf[i].pass.replace(j, 1, "%");
        for (int j = 0; j < 10; j++)
            if (loc3[j] != 0)
                inf[i].pass.replace(j, 1, "L");
        for (int j = 0; j < 10; j++)
            if (loc4[j] != 0)
                inf[i].pass.replace(j, 1, "o");
    }
    if (N == 0) {
        if (M == 1)
            cout << "There is 1 account and no account is modified";
        else
            cout << "There are " << M << " accounts and no account is modified";
    }
    else {
        cout << N << endl;
        for (int i = 0; i < M; i++) {
            if (x[i] == 1)
                cout << inf[i].user << " " << inf[i].pass << endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值