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\n",pass[j]);
            if(pass[j]=='1'){
//printf("1->@\n");
                flag=false;
                pass[j]='@';
            }
            else if(pass[j]=='0'){
//printf("0->\%\n");
                flag=false;
                pass[j]='%';
            }
            else if(pass[j]=='l'){
//printf("l->L\n");
                flag=false;
                pass[j]='L';
            }
            else if(pass[j]=='O'){
//printf("O->o\n");
                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",n);
        else
            printf("There are %d accounts and no account is modified\n",n);
    }
    else{
        printf("%d\n",cnt);
        for(int i=0;i<cnt;i++){
            printf("%s %s\n",ans[i].team,ans[i].pass);
        }
    }
    return 0;
}
View Code

 

posted @ 2017-04-29 22:30  辰曦~文若  阅读(230)  评论(0编辑  收藏  举报