PAT-A 1035. Password (20)

题目链接在此

题意理解

给定N个用户的用户名(name)和密码(pwd),现在需要按照如下修改规则,对需要修改密码的用户信息进行修改,修改规则如下:
1(数字1) ->@
0(数字0) ->%
l(小写L) ->L
O(大写字母O) ->o(小写字母o)
之后,输出修改过的用户信息的个数和对应的信息(用户名 密码)
如果没有任何用户的信息得到了修改,则根据单复数输出”There is(are) N account(s) and no account is modified”

以上加粗就是需要注意的地方。

思路

定义INFO结构体数组(包含name字符数组和pwd字符数组),申请一个零时的INFO变量temp,用它来保存每次的输入;定义一个INFO型数组info[],将修改过后的用户信息存入其中。之后根据题意输出即可。

AC代码

#include<stdio.h>
#include<string.h>

struct INFO{
    char name[11];
    char pwd[11];
}info[1001];


int main(){

    INFO temp;
    int N;
    int M = 0;

    scanf("%d",&N);

    bool flag; //是否modify的标志 
    for(int i = 0 ; i < N; i++){
        scanf("%s %s",temp.name,temp.pwd);

        flag = false;

        //modify 
        for(int j = 0; j < strlen(temp.pwd); j++){
            if(temp.pwd[j] == '1'){
                temp.pwd[j] = '@';
                flag = true;
            }else if(temp.pwd[j] == '0'){
                temp.pwd[j] = '%';
                flag = true;
            }else if(temp.pwd[j] == 'l'){
                temp.pwd[j] = 'L';
                flag = true;
            }else if(temp.pwd[j] == 'O'){
                temp.pwd[j] = 'o';
                flag = true;
            }
        }

        //& if modified, put it into info[] 
        if(flag){
            info[M++] = temp;
        }
    }


    if(M==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",M);
        for(int i = 0; i < M; i++){
            printf("%s %s\n",info[i].name,info[i].pwd);
        }   
    }


    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值