結果

問題 No.39 桁の数字を入れ替え
ユーザー satanicsatanic
提出日時 2016-03-14 18:49:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,334 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 67,748 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 05:21:00
合計ジャッジ時間 1,358 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	enum check {
		CHECK, UNDECIDED, ENDED,
	};

	char tmp;
	check check_f = UNDECIDED;
	std::vector<int> input;
	while (std::cin >> tmp) {
		input.push_back(tmp-'0');
	}
	std::vector<int> part_input(input);
	while(check_f==UNDECIDED) {
		for (auto it = part_input.begin() + 1; it != part_input.end(); ++it) {
			if (part_input.front() < *it) {
				check_f = CHECK;
				break;
			}
		}
		if (check_f != CHECK) {
			part_input.erase(part_input.begin());
			if (part_input.empty()) {
				check_f = ENDED;
			}
		}
		
	}
	//チェック
	std::vector<int> max_checker(part_input);
	std::sort(max_checker.begin(), max_checker.end());
	for (auto it = part_input.rbegin(); it != part_input.rend() && check_f != ENDED; ++it) {
		if (*it == max_checker.back()) {
			for (auto it2 = part_input.begin(); it2 != part_input.end(); ++it2) {
				if (*it2 != max_checker.back() || *it == *it2) {
					std::swap(*it, *it2);
					auto it3 = input.rbegin();
					for (auto it4 = part_input.rbegin(); it4 != part_input.rend(); ++it4, ++it3) {
						*it3 = *it4;
					}
					check_f = ENDED;
					break;
				}
			}
		}
	}
	//出力
	for (auto it : input) {
		std::cout << it;
	}
	std::cout << "\n";

	return 0;
}
0