sdnuoj 1106
想不到我用map做出来了
#include<bits/stdc++.h>
using namespace std;
struct zimu
{
char x;
int y;
}r[100];
bool cmp(zimu a,zimu b)
{
if(a.y != b.y)return a.y>b.y;
return a.x<b.x;
}
int main()
{
string s;
map<char,int> a;
while(cin>>s)
{
a['A']=0;
a['B']=0;
a['C']=0;
a['D']=0;
a['E']=0;
a['F']=0;
a['G']=0;
a['H']=0;
a['I']=0;
a['J']=0;
a['K']=0;
a['A']=0;
a['A']=0;
a['L']=0;
a['M']=0;
a['N']=0;
a['O']=0;
a['P']=0;
a['Q']=0;
a['R']=0;
a['S']=0;
a['T']=0;
a['U']=0;
a['V']=0;
a['W']=0;
a['X']=0;
a['Y']=0;
a['Z']=0;
for(int i = 0; i<100; i++) r[i].y = 0;
int len=s.length();
for(int i=0;i<len;i++)
{
if(s[i] >= 'a' && s[i] <= 'z') s[i]=s[i]-32;
}
for(int i=0;i<len;i++)a[s[i]]++;
for(int j=0,i=65;j<26;j++)
{
r[j].x = (char)i;
i++;
}
for(int i=0;i<26;i++)
{
r[i].y=a[r[i].x];
//cout<<r[i].y<<endl;
}
sort(r,r+26,cmp);
for(int i=0;i<26;i++)
{
if(r[i].y==0) continue;
cout<<r[i].x<<' '<<r[i].y<<endl;
}
cout<<"---"<<endl;
//for(int i=0;i<len;i++)cout<<a[s[i]]<<endl;
}
return 0;
}