結果

問題 No.8116 TCP ソート
ユーザー elphe
提出日時 2025-04-03 12:05:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 1,070 ms
コンパイル使用メモリ 85,360 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-04-03 12:05:15
合計ジャッジ時間 1,831 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>

using namespace std;

static inline const string& solve(string& S) noexcept
{
	vector<uint32_t> count_of(128, 0);
	uint32_t i;
	for (i = 0; i != S.size(); ++i)
		++count_of[S[i]];

	if (count_of['C'] == 0)
	{
		for (i = 0; count_of['P'] != 0; --count_of['P'], ++i)
			S[i] = 'P';
		for (; count_of['T'] != 0; --count_of['T'], ++i)
			S[i] = 'T';
	}
	else
	{
		for (i = 0; count_of['T'] != 0; --count_of['T'], ++i)
			S[i] = 'T';
		for (; count_of['C'] != 0; --count_of['C'], ++i)
			S[i] = 'C';
		for (; count_of['P'] != 0; --count_of['P'], ++i)
			S[i] = 'P';
	}

	return S;
}

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	string S;
	S.reserve(100), cin >> S;

	cout << solve(S) << '\n';
	return 0;
}
0