PAT (Advanced) 1035. Password (20)

原题:1035. Password (20)


解题思路:

按题意进行即可,注意一个陷阱:样例在没有修改时n = 1与n > 1输出不同即可。


代码如下:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1000 + 5;
struct student
{
    char id[15];
    char password[15];
    int check;
} stu[maxn];

bool check(char& a)
{
    if(a == '1') {a = '@'; return true;}
    if(a == 'l') {a = 'L'; return true;}
    if(a == '0') {a = '%'; return true;}
    if(a == 'O') {a = 'o'; return true;}
    return false;
}

bool trans(char s[], int len)
{
    bool flag = false;
    for(int i = 0; i < len; i++)
        if(check(s[i])) flag = true;
    return flag;
}

int main()
{
    int n;
    while(scanf("%d", &n) == 1)
    {
        for(int i = 0; i < n; i++)
        {
            scanf("%s%s", stu[i].id, stu[i].password);
            stu[i].check = 0;
        }
        int cnt = 0;
        for(int i = 0; i < n; i++)
        {
            int len = strlen(stu[i].password);
            if(trans(stu[i].password, len)){cnt++; stu[i].check = 1;}
        }
        int i = 0;
        if(cnt == 0 && n > 1) printf("There are %d accounts and no account is modified\n", n);
        else if (cnt == 0) printf("There is %d account and no account is modified\n", n);
        else
        {
            printf("%d\n", cnt);
            while(cnt)
            {
                if(stu[i].check) { printf("%s %s\n", stu[i].id, stu[i].password); cnt--;}
                i++;
            }
        }
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值