#include<algorithm>
using namespace std;
struct array{
int ascii;
int fre;
} a[128];
bool compare(array c1,array c2)
{
if(c1.fre<c2.fre)
return true;
else if((c1.fre==c2.fre)&&(c1.ascii>c2.ascii))
return true;
return false;
}
int main()
{
char ch;
int i,f=0,n=0,m;
//freopen("in.txt","r",stdin);
n=scanf("%c",&ch);
while(1)
{
m=(int)ch;
while(m!=10) // 10='\n'
{
if(m>31 && m<128)
{
a[m].ascii=m;
a[m].fre+=1;
}
n=scanf("%c",&ch);
if(n!=1)
break;
m=(int)ch;
}
sort(a+32,a+127,compare);
for(i=32;i<128;i++)
{
if(a[i].fre!=0)
{
printf("%d %d\n",a[i].ascii,a[i].fre);
a[i].ascii=0;
a[i].fre=0;
}
}
n=scanf("%c",&ch);
if(n!=1)
break;
printf("\n");
}
return 0;
}
No comments:
Post a Comment