PAT B1043出力PATest(20分)

トピックリンクhttps://pintia.cn/problem-sets/994805260223102976/problems/994805280074743808

タイトル説明が
ない以上10 ^ 4の長さ、文字のみからなる文字列を考えます。文字の順出力に... PATestPATestに従って、順番を再調整し、他の文字を無視してください。もちろん、文字の6種類の数は、文字出力のいくつかの種類が終了した場合、すべての文字までPATestプリントの順に基づいて、残りの文字が出力され、必ずしも限りではありません。

入力
入力は、英語の文字からなる唯一の非空の文字列、行の以上10 ^ 4の長さが与えられます。

出力
トピック文字列の出力順序の要件によって行インチ トピックは、出力が空でないことを確認してください。

サンプル入力
redlesPayBestPATTopTeePHPereatitAPPT

サンプル出力
PATestPATestPTetPTePePee

コード

#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
	map<char, int> m;
	m['P'] = 0; m['A'] = 0; m['T'] = 0; m['e'] = 0; m['s'] = 0; m['t'] = 0; 
	char str[7] = {'P', 'A', 'T', 'e', 's', 't'};
	bool flag = true;
	string s1;
	getline(cin, s1);
	for(int i = 0; i < s1.size(); i++)
		if(s1[i] == 'P' || s1[i] == 'A' || s1[i] == 'T' || s1[i] == 'e' || s1[i] == 's' || s1[i] == 't')
			m[s1[i]]++;
	while(flag) {
		flag = false;
		for(int i = 0; i < 6; i++) {
			if(m[str[i]] > 0) {
				cout << str[i];
				m[str[i]]--;
				flag = true;
			}
		}
	}
	cout<<endl;
	return 0;
}
公開された288元の記事 ウォン称賛12 ビュー20000 +

おすすめ

転載: blog.csdn.net/Rhao999/article/details/104668237