HJ20 密码验证合格程序

提示:文章

文章目录

前言

前期疑问:
本文目标:


一、背景

最近

二、

2.1

HJ20 密码验证合格程序

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

typedef struct
{
    char character;
    int count;
}DataInfo;

int compare(const void *a, const void *b)
{
    if(((DataInfo*)a)->count == ((DataInfo*)b)->count)
    {
        return ((DataInfo*)a)->character - ((DataInfo*)b)->character;
    }

    return ((DataInfo*)b)->count - ((DataInfo*)a)->count;
}

int main() {
    int a, b;
    DataInfo info[150];
    memset(info, 0, sizeof(info));
    char strArray[1001] = {'\0'};
    while (scanf("%s", strArray) != EOF) { // 注意 while 处理多个 case
        // 64 位输出请用 printf("%lld") to 
        //printf("%s\n", strArray);
        int len = strlen(strArray);
        for(int i = 0; i < len; i++)
        {
            info[strArray[i]].character = strArray[i];
            info[strArray[i]].count++;
        }

        qsort(info, 150, sizeof(DataInfo), compare);
        for(int  i = 0; i < 150; i++)
        {
            if(info[i].count)
            {
                printf("%c", info[i].character);
            }
        }
    }


    return 0;
}

哎,各种出神,比如写成return ((DataInfo*)a)->character - ((DataInfo*)a)->character;感觉下次还有可能写错。。。。。


总结

未完待续

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值