【PAT】A1035. Password (20)

本文介绍了一个简单的密码加密程序,该程序使用C语言实现,并通过特定规则替换密码中的字符以增加安全性。文章展示了如何读取用户的账号和原始密码,并对密码进行加密处理。如果密码被修改,则会显示修改后的密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A1035. Password (20)

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

struct team{
    char name[20], pwd[20];
    int ischange;
}teams[1000];

void pwdcrypt(struct team *t, int *counter){
    int len = (int)strlen(t->pwd);
    for(int i = 0; i < len; i++){
        switch (t->pwd[i]) {
            case '1':
                t->pwd[i] = '@';
                t->ischange = 1;
                break;
            case '0':
                t->pwd[i] = '%';
                t->ischange = 1;
                break;
            case 'l':
                t->pwd[i] = 'L';
                t->ischange = 1;
                break;
            case 'O':
                t->pwd[i] = 'o';
                t->ischange = 1;
                break;
            default:
                break;
        }
    }
    if(t->ischange == 1)
        *counter += 1;
}

int main(int argc, const char * argv[]) {

    int N;
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        scanf("%s %s", teams[i].name, teams[i].pwd);
        teams[i].ischange = 0;
    }

    int counter = 0;
    for(int i = 0; i < N; i++){
        pwdcrypt(&teams[i], &counter);
    }

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

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值