博客
关于我
1035 Password (20分)
阅读量:373 次
发布时间:2019-03-05

本文共 1679 字,大约阅读时间需要 5 分钟。

为了解决账号和密码中的混淆字符问题,我们需要编写一个程序来检查并替换这些字符。程序的主要任务是读取输入的账号信息,识别出需要替换的字符,并将其替换为指定的字符。最后,输出替换后的账号信息。

方法思路

  • 读取输入:首先读取输入的测试用例数N,然后依次读取每个账号的用户名和密码。
  • 替换字符:对于每个账号,分别处理用户名和密码,替换字符'1'为'@','0'为'%', 'l'为'L', 'O'为'o'。
  • 比较和记录:比较替换后的用户名和密码与原用户名和密码。如果有任何一个部分发生了变化,则记录该账号作为被修改的结果。
  • 输出结果:根据被修改的账号数量,输出相应的结果。如果没有账号被修改,输出特定的语句;如果有账号被修改,输出被修改的账号信息。
  • 解决代码

    #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;}

    代码解释

  • replace函数:该函数遍历输入字符串中的每个字符,检查是否需要替换,并将字符替换为指定的字符。返回替换后的新字符串。
  • 读取输入:使用getline函数读取每一行,分割用户名和密码。
  • 处理和比较:对用户名和密码分别进行替换,比较替换后的字符串与原字符串是否相同。如果不同,则记录该账号。
  • 输出结果:根据被修改的账号数量,输出相应的结果。如果没有账号被修改,输出特定的语句;如果有账号被修改,输出被修改的账号信息。
  • 转载地址:http://pdag.baihongyu.com/

    你可能感兴趣的文章
    nginx 集群配置方式 静态文件处理
    查看>>
    nginx+mysql+redis+mongdb+rabbitmq 自动化部署脚本
    查看>>
    nginx+php的搭建
    查看>>
    nginx+tomcat+memcached
    查看>>
    Nginx+Tomcat实现动静分离
    查看>>
    nginx+Tomcat性能监控
    查看>>
    nginx+uwsgi+django
    查看>>
    nginx+vsftp搭建图片服务器
    查看>>
    Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
    查看>>
    nginx-vts + prometheus 监控nginx
    查看>>
    nginx: [emerg] getpwnam(“www”) failed 错误处理方法
    查看>>
    nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
    查看>>
    nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
    查看>>
    Nginx、HAProxy、LVS
    查看>>
    Nginx下配置codeigniter框架方法
    查看>>
    Nginx中使用expires指令实现配置浏览器缓存
    查看>>
    nginx中配置root和alias的区别
    查看>>
    Nginx之二:nginx.conf简单配置(参数详解)
    查看>>
    Nginx从入门到精通
    查看>>
    Nginx代理websocket配置(解决websocket异常断开连接tcp连接不断问题)
    查看>>