sdnu1106

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值