zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    “==” 和 Equals()
    数据持久层的设计
    Jquery Validation :多个按钮都需要做提交验证的解决方案
    留住异常的堆栈信息【throw ex 和 throw 的区别】
    [转] eval() may be evil
    框架结构和脚本跨域的问题
    ue4 材质MipLevels
    spring+json+jquery
    a different object with the same identifier value was already associated with the session错误
    kali 更新国内apt源 (转)
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11374208.html
Copyright © 2011-2022 走看看