【PAT】1035 Password (20 分)

46 篇文章 0 订阅
44 篇文章 0 订阅
  • 题目大意:检查密码里是否有1、l、0、o,如果检测到了就分别replace 1 (one) by @, 0 (zero) by %, l by L, and O by o

  • 知识点:

    1. string
    2. vector:
      1. v.pushback(1):往v最后面插入一个1
        python里是v.append(1)
  • 代码:

    #include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
    
    int main(){
        int n, cnt = 0;
        string account, passport;
        vector<string> a, p;
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> account >> passport;
            bool flag = false;
            for(int j = 0; j < passport.length(); j++){
                if(passport[j] == '1' || passport[j] == 'l' || passport[j] == '0' || passport[j] == 'O'){
                    flag = true;
                    if(passport[j] == '1')  passport[j] = '@';
                    if(passport[j] == 'l')  passport[j] = 'L';
                    if(passport[j] == '0')  passport[j] = '%';
                    if(passport[j] == 'O')  passport[j] = 'o';
                }
            }
            if(flag){
                cnt++;
                a.push_back(account);
                p.push_back(passport);
            }
        }
        if(cnt == 0)
            if(n == 1)  printf("There is 1 account and no account is modified");
            else    printf("There are %d accounts and no account is modified", n);
        else{
            cout << cnt << endl;
            for(int i = 0; i < cnt; i++)
                printf("%s %s\n", a[i].c_str(), p[i].c_str());
        }
        return 0;
    }
    
  • 总结:

    1. 注意输出格式!!!

      n = 1:are变is,accounts变account。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值