PAT (Basic Level) 1043 输出PATest

题意

输出所有PATest,不足亦输出,但是序不变。

思路

水~

代码

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	string s;
	cin >> s;
	vector<char> tmp = {'P', 'A', 'T', 'e', 's', 't'};
	vector<int> cnt(6);
	for (int i = 0; i < s.size(); ++i) {
		for (int j = 0; j < 6; ++j) {
			if (s[i] == tmp[j]) cnt[j]++;
		}
	}
	int maxn = *max_element(cnt.begin(), cnt.end());
	for (int i = 0; i < maxn; ++i) {
		for (int j = 0; j < 6; ++j) {
			if (cnt[j] == 0) continue;
			cout << tmp[j];
			cnt[j]--;
		}
	}
	cout << '\n';
	return 0;
} 

HINT

不定时更新更多题解,Basic Level 全部AC代码,详见 link ! ! !

发布了50 篇原创文章 · 获赞 15 · 访问量 2663

猜你喜欢

转载自blog.csdn.net/abcdefbrhdb/article/details/104593917