pat 1035 Password (20分)

在这里插入图片描述
字符串模拟题:
注意提议就好了

#include <iostream>
using namespace std;
#include <vector>
int main() {
    int m;
    cin >> m;
    string id, pwd;
    vector<string> p, I;
    int cnt = 0;
    while(m--) {
        bool flag = false;
        //记录次数,后面为了方便表达
        cin >> id >> pwd;
        cnt++;
        for(int i = 0; i < pwd.size(); i++) {
            if(pwd[i] == '1' || pwd[i] == '0' || pwd[i] == 'l' || pwd[i] == 'O') {
                if(pwd[i] == '1') pwd[i] = '@';
                if(pwd[i] == '0')pwd[i] = '%';
                if(pwd[i] == 'l') pwd[i] = 'L';
                if(pwd[i] == 'O') pwd[i] = 'o';
                flag = true;
            }
        }
        if(flag) {
            I.push_back(id);
            p.push_back(pwd);
        }

    }
    if(!p.size()) {
        cout << "There"<<(cnt==1?" is ":" are ") << cnt <<(cnt==1?" account":" accounts")<<" and no account is modified";
    }
    else {
        cout <<p.size()<<endl;
        for(int i = 0; i < p.size(); i++) {
                cout<<I[i]<<" "<<p[i]<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44110100/article/details/106815400