提示:文章
文章目录
前言
前期疑问:
本文目标:
一、背景
最近
二、
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;感觉下次还有可能写错。。。。。
总结
未完待续