#include<stdio.h>
#include<algorithm>
#include<cstring>
using namespace std;
struct keep
{
int charecter=0;
int cont=0;
};
keep arr[200];
bool comp(keep x,keep y)
{
if(x.cont==y.cont)
return x.charecter > y.charecter;
return x.cont < y.cont;
}
int main()
{
char str[9999];
int len,i,tag=0;
while(gets(str))
{
len= strlen(str);
if(tag>0)
{
printf("\n");
}
tag++;
for(i=0; i<200; i++)
{
arr[i].charecter=0;
arr[i].cont=0;
}
for(i=0; i<len; i++)
{
arr[str[i]].charecter=str[i];
arr[str[i]].cont++;
}
sort(arr,arr+200,comp);
for(i=0; i<200; i++)
{
if(arr[i].cont!=0)
printf("%d %d\n",arr[i].charecter,arr[i].cont);
}
memset(str,'\0',sizeof(str));
}
return 0;
}
#include<algorithm>
#include<cstring>
using namespace std;
struct keep
{
int charecter=0;
int cont=0;
};
keep arr[200];
bool comp(keep x,keep y)
{
if(x.cont==y.cont)
return x.charecter > y.charecter;
return x.cont < y.cont;
}
int main()
{
char str[9999];
int len,i,tag=0;
while(gets(str))
{
len= strlen(str);
if(tag>0)
{
printf("\n");
}
tag++;
for(i=0; i<200; i++)
{
arr[i].charecter=0;
arr[i].cont=0;
}
for(i=0; i<len; i++)
{
arr[str[i]].charecter=str[i];
arr[str[i]].cont++;
}
sort(arr,arr+200,comp);
for(i=0; i<200; i++)
{
if(arr[i].cont!=0)
printf("%d %d\n",arr[i].charecter,arr[i].cont);
}
memset(str,'\0',sizeof(str));
}
return 0;
}
No comments:
Post a Comment