本文共 1679 字,大约阅读时间需要 5 分钟。
为了解决账号和密码中的混淆字符问题,我们需要编写一个程序来检查并替换这些字符。程序的主要任务是读取输入的账号信息,识别出需要替换的字符,并将其替换为指定的字符。最后,输出替换后的账号信息。
#include#include #include #include using namespace std;string replace(string s) { string res; for (char c : s) { if (c == '1') { res += '@'; } else if (c == '0') { res += '%'; } else if (c == 'l') { res += 'L'; } else if (c == 'O') { res += 'o'; } else { res += c; } } return res;}int main() { int N; cin >> N; vector > accounts; for (int i = 0; i < N; ++i) { string line; size_t space_pos = line.find(' '); string id = line.substr(0, space_pos); string ps = line.substr(space_pos + 1); string new_id = replace(id); string new_ps = replace(ps); if (new_id != id || new_ps != ps) { accounts.push_back(make_pair(new_id, new_ps)); } } int M = accounts.size(); if (M == 0) { if (N == 1) { cout << "There is 1 account and no account is modified"; } else { cout << "There are " << N << " accounts and no account is modified"; } } else { cout << M << endl; for (auto &acc : accounts) { cout << acc.first << ' ' << acc.second << endl; } } return 0;}
getline
函数读取每一行,分割用户名和密码。转载地址:http://pdag.baihongyu.com/