PAT乙级1043

题目链接

实现

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char** argv) {
	int count[6]={0};//分别用来统计 P A T e s t 的数量
	string putstr="PATest";
	string str;
	cin>>str;
	int len=strlen(str.c_str());
	for(int i=0;i<len;i++)
	{
		if(putstr.find(str[i])!=string::npos)
		{
			if(str[i]=='P')
				count[0]+=1;
			else if(str[i]=='A')
				count[1]+=1;
			else if(str[i]=='T')
				count[2]+=1;
			else if(str[i]=='e')
				count[3]+=1;
			else if(str[i]=='s')
				count[4]+=1;
			else if(str[i]=='t')
				count[5]+=1;
		}	
		else
			continue;
	}
	
	int i,max=0;	//max用来记录出现次数最多的字母 
	for(i=0;i<6;i++)
	{
		if(count[i]>max)
			max=count[i]; 
	} 
	for(i=0;i<max*6;i++)
	{
		if(count[i%6]>0)
		{
			switch(i%6)
			{
				case 0:cout<<"P";break;
				case 1:cout<<"A";break;
				case 2:cout<<"T";break;
				case 3:cout<<"e";break;
				case 4:cout<<"s";break;
				case 5:cout<<"t";break;
			}
			count[i%6]--;
		}
		
	} 

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值