PAT A1035 Password (20 分) 字符串

本文介绍了一种字符串处理算法,用于判断并替换指定字符。通过使用C++编程语言,实现了一个用户账号管理系统,该系统能够识别并修改包含特定字符的密码,确保密码安全性。

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

    题目大意:判断给出的字符串中是否有指定的字符,如果有,替换掉这些字符并输出。

    直接替换就好。

AC代码:

#include <iostream>
#include <vector>
#include <map>

using namespace std;

bool modified(string &str, map<char, char>&mp)
{
    bool ret = false;
    for (int i = 0; i < str.size(); ++i)
    {
        if(str[i] == '1' || str[i] == '0' || str[i] == 'l' || str[i] == 'O')
        {
            str[i] = mp[str[i]];
            ret = true;
        }
    }
    return ret;
}

struct user
{
    string id;
    string password;
    user(string id, string password):id(id), password(password){};
};

int main()
{
    map<char, char>mp;
    mp['1'] = '@';
    mp['0'] = '%';
    mp['l'] = 'L';
    mp['O'] = 'o';
    int N;
    cin >> N;
    vector<user> v;
    for (int i = 0; i < N; ++i)
    {
        string id, password;
        cin >> id >> password;
        if(modified(password,mp)) v.push_back(user(id, password));
    }
    if(v.size() > 0)
    {
        cout << v.size() << endl;
        for (int i = 0; i < v.size(); ++i)
        {
            cout << v[i].id << " " << v[i].password << endl;
        }
    }
    else
    {
        if(N == 1) cout << "There is 1 account and no account is modified";
        else cout << "There are " << N << " accounts and no account is modified";
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值