1035 Password

本文介绍了一个编程挑战,旨在解决由易混淆字符导致的密码问题。挑战要求将特定字符(如1,0,l,O)替换为不易混淆的符号(@,%L,o),并提供了一个C++实现示例,展示了如何检查和修改密码。

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

1035 Password (20 point(s))

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.

题意

​ 有一些很难区分,1 和L 0和O等。

​ replace 1 (one) by @, 0 (zero) by %, l by L, and O by o.

​ 没别的。注意结果输出的时候 is 和are 还有单复数

if(CNT==1)
    cout<<"There is "<<CNT<<" account and no account is modified"<<endl;
else
    cout<<"There are "<<CNT<<" accounts and no account is modified"<<endl;
    

#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Node{
    string name;
    string pwd;
};
int CNT;
vector<Node> res;
bool replace(string &s){
    bool ret =false;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){s[i]='@';ret =true;}
        else if(s[i]=='0'){s[i]='%';ret =true;}
        else if(s[i]=='l'){s[i]='L';ret =true;}
        else if(s[i]=='O'){s[i]='o';ret =true;}
    }
    return ret;
}
int main(){

    cin>>CNT;
    string temp_name,temp_pwd;
    for(int i=0;i<CNT;i++){
        cin>>temp_name>>temp_pwd;
        if(replace(temp_pwd)){
            res.push_back(Node{temp_name,temp_pwd});
        }
    }
    if(res.size()){
        cout<<res.size()<<endl;
        for(int i=0;i<res.size();i++){
            cout<<res[i].name<<" "<<res[i].pwd<<endl;
        }
    }
    else{
        if(CNT==1)
            cout<<"There is "<<CNT<<" account and no account is modified"<<endl;
        else{
            cout<<"There are "<<CNT<<" accounts and no account is modified"<<endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值