zoukankan      html  css  js  c++  java
  • PAT甲题题解-1035. Password (20)-水

    题意:
    给n个用户名和密码,把密码中的1改为@,0改为%,l改为L,O改为o。

    让你输出需要修改密码的用户名个数,以及对应的用户名和密码,按输入的顺序。
    如果没有用户需要修改,则输出对应的语句,注意单复数。。。

    没啥好说的,就for一遍密码,把需要改的改下,存入到ans中去。

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <string.h>
    #include <cmath>
    using namespace std;
    const int maxn=1000+5;
    struct Node{
        char team[15];
        char pass[15];
    }ans[maxn];
    int main()
    {
        int n;
        int cnt=0;
        char team[20],pass[20];
        scanf("%d",&n);
        bool flag;
        for(int i=0;i<n;i++){
            scanf("%s %s",team,pass);
            flag=true;
            int len=strlen(pass);
            for(int j=0;j<len;j++){
    //printf("%c
    ",pass[j]);
                if(pass[j]=='1'){
    //printf("1->@
    ");
                    flag=false;
                    pass[j]='@';
                }
                else if(pass[j]=='0'){
    //printf("0->\%
    ");
                    flag=false;
                    pass[j]='%';
                }
                else if(pass[j]=='l'){
    //printf("l->L
    ");
                    flag=false;
                    pass[j]='L';
                }
                else if(pass[j]=='O'){
    //printf("O->o
    ");
                    flag=false;
                    pass[j]='o';
                }
            }
            if(!flag){
                strcpy(ans[cnt].team,team);
                strcpy(ans[cnt].pass,pass);
                cnt++;
            }
        }
        if(cnt==0){
            if(n==1)
                printf("There is %d account and no account is modified
    ",n);
            else
                printf("There are %d accounts and no account is modified
    ",n);
        }
        else{
            printf("%d
    ",cnt);
            for(int i=0;i<cnt;i++){
                printf("%s %s
    ",ans[i].team,ans[i].pass);
            }
        }
        return 0;
    }
    View Code
  • 相关阅读:
    PAT 05-树7 File Transfer
    PAT 05-树6 Path in a Heap
    PAT 10-2 删除字符串中的子串
    PAT 10-1 在字符串中查找指定字符
    PAT 10-0 说反话
    PAT 08-2 求矩阵的局部最大值
    PAT 07-3 求素数
    PAT 07-2 A+B和C
    PAT 07-0 写出这个数
    PAT 06-3 单词长度
  • 原文地址:https://www.cnblogs.com/chenxiwenruo/p/6786509.html
Copyright © 2011-2022 走看看