其他分享
首页 > 其他分享> > 1043. 输出PATest

1043. 输出PATest

作者:互联网

1043. 输出PATest

给定⼀个⻓度不超过10000的、仅由英⽂字⺟构成的字符串。请将字符重新调整顺序, 按“PATestPATest….”这样的顺序输出,并忽略其它字符。当然,六种字符的个 数不⼀定是⼀样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印, 直到所有字符都被输出。

输⼊格式:

输⼊在⼀⾏中给出⼀个⻓度不超过10000的、仅由英⽂字⺟构成的⾮空字符串。

输出格式:

在⼀⾏中按题⽬要求输出排序后的字符串。题⽬保证输出⾮空。

输⼊样例:

redlesPayBestPATTopTeePHPereatitAPPT

输出样例:

PATestPATestPTetPTePePee

分析:

将字符串的每⼀个字符出现的个数保存在map中,然后依次输出PATest,每次输出⼀次 字符就将map对应的字符个数减1

#include <bits/stdc++.h>
using namespace std;
int main() {
	map<char,int>mp;
	string s;getline(cin,s);
	for(int i=0;i<s.size();i++) mp[s[i]]++;
	while(mp['P']>0||mp['A']>0||mp['T']>0||mp['e']>0||mp['s']>0||mp['t']>0){
		if(mp['P']-- >0) cout<<'P';
		if(mp['A']-- >0) cout<<'A';
		if(mp['T']-- >0) cout<<'T';
		if(mp['e']-- >0) cout<<'e';
		if(mp['s']-- >0) cout<<'s';
		if(mp['t']-- >0) cout<<'t'; 
	}
	return 0;
}

标签:1043,输出,字符,mp,cout0,字符串,PATest
来源: https://blog.csdn.net/weixin_52834435/article/details/122775430