还是找你帮我编个程序,我最近用脑过度- -
输入一串字符,以“?”结束,统计各字母出现的次数,并按字母出现的多少输出
先输出字母出现多的,次数相同的按照字母表顺序输出,不出现的不输出
主要是后面那句的- -要求
输入一串字符,以“?”结束,统计各字母出现的次数,并按字母出现的多少输出
先输出字母出现多的,次数相同的按照字母表顺序输出,不出现的不输出
主要是后面那句的- -要求
#include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct Node{ int x; char c; }Node; int cmp (const void* a,const void *b) { if((*(Node*)a).x==(*(Node*)b).x) return (*(Node*)b).c - (*(Node*)a).c; else return (*(Node*)b).x - (*(Node*)a).x; } int main() { int i; Node num[125]; char c; memset(num,0,sizeof(num)); while((c=getchar())!='?') { num[c-'0'].x++; num[c-'0'].c = c; } qsort(num,125,sizeof(num[0]),cmp); for(i=0;i<125;i++) if(num[i].x>=1 && ((num[i].c>='a' && num[i].c<='z') || (num[i].c>='A' && num[i].c<='Z'))) printf("%c\n",num[i].c); return 0; }