• PAT A1035 Password (20)


    AC代码

    • 注意创造函数条件中使用引用
    • 输出语句注意单复数
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    struct Usr {
        bool flag;
        char id[20];
        char pwd[20];
    }usr[1010];
    
    void modify(Usr& a) { //参数使用了引用&,可以对传入参数进行修改
        for(int i = 0; i < 10; i++) {
            char b = a.pwd[i];
            if(b == '1') {
                a.pwd[i] = '@';
                a.flag = 0;
            }
            if(b == '0') {
                a.pwd[i] = '%';
                a.flag = 0;
            }
            if(b == 'l') {
                a.pwd[i] = 'L';
                a.flag = 0;
            }
            if(b == 'O') {
                a.pwd[i] = 'o';
                a.flag = 0;
            }
        }
    }
    void init_flag(Usr& a) {
        a.flag = 1;
    }
    
    int main() {
        #ifdef ONLINE_JUDGE
        #else
            freopen("1.txt", "r", stdin);
        #endif // ONLINE_JUDGE
        int n;
        scanf("%d", &n); //输入密码数量
        for(int i = 0; i < n; i++) {
            scanf("%s %s", usr[i].id, usr[i].pwd);
        }
    //    for(int i = 0; i < n; i++) {
    //        printf("%s %s
    ", usr[i].id, usr[i].pwd);
    //    }
    //    printf("------------------------------
    ");
        int num = 0; //需要修改的密码数量
        //初始化flag
        for(int i = 0; i <= n; i++) {
            init_flag(usr[i]);
    //        printf("init:%s %s %d
    ", usr[i].id, usr[i].pwd, usr[i].flag);
            modify(usr[i]);
    //        printf("%s %s %d
    ", usr[i].id, usr[i].pwd, usr[i].flag);
            if(usr[i].flag == 0) {
                num++;
            }
        }
    //    printf("------------------------------
    ");
    //    for(int i = 0; i < n; i++) {
    //        printf("%s %s %d
    ", usr[i].id, usr[i].pwd, usr[i].flag);
    //    }
    //    printf("------------------------------
    ");
    //    printf("%d
    ", num);
        if(num != 0) {
            printf("%d
    ", num);
            for(int i = 0; i <= n; i++) {
                if(usr[i].flag == 0) {
                    printf("%s %s
    ", usr[i].id, usr[i].pwd);
                }
            }
        } else if(n == 1){
            printf("There is %d account and no account is modified", n);
        } else if(n > 1) {
            printf("There are %d accounts and no account is modified", n);
        }
        return 0;
    }
    
  • 相关阅读:
    [P4721] 【模板】分治 FFT
    [GYM102452E] Erasing Numbers
    [LOJ6220] sum
    [CF776B] Sherlock and His Girlfriend
    [LOJ6087] 毒瘤题
    [LOJ2612] 花匠
    [LOJ529] 自然语言
    [CTSC2017] 吉夫特
    [LOJ6671] EntropyIncreaser 与 Minecraft
    [LOJ3196] 挂架
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11374208.html
Copyright © 2020-2023  润新知