PATA 1035 Password

在这里插入图片描述
在这里插入图片描述
很常规的字符串处理
其实这道题用find(str)和replace(it1,it2,str2)也可以,但是仔细想想其实还不如自己循环然后手动if方便呢
代码如下

#include <iostream>
#include <string>
using namespace std;

const int MaxN=1000+5;

struct account{
    string name,password;
    bool modify=false;//默认没有被修改
};

int main()
{
    account student[MaxN];
    int N,count=0;//count是被修改的数量
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>student[i].name>>student[i].password;
        for(int j=0;j<student[i].password.size();j++){
            if(student[i].password[j]=='1'){
                student[i].password[j]='@';
                student[i].modify=true;
            }
            else if(student[i].password[j]=='0'){
                student[i].password[j]='%';
                student[i].modify=true;
            }
            else if(student[i].password[j]=='l'){
                student[i].password[j]='L';
                student[i].modify=true;
            }
            else if(student[i].password[j]=='O'){
                student[i].password[j]='o';
                student[i].modify=true;
            }

        }
        if(student[i].modify==true)//被修改了count++
            count++;
    }
    if(count==0&&N==1)
        cout<<"There is 1 account and no account is modified"<<endl;
    else if(count==0)
        cout<<"There are "<<N<<" accounts and no account is modified"<<endl;
    else{
        cout<<count<<endl;
        for(int i=0;i<N;i++){
            if(student[i].modify==true)
                cout<<student[i].name<<" "<<student[i].password<<endl;
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值