結果

問題 No.39 桁の数字を入れ替え
ユーザー satanic
提出日時 2016-03-14 04:28:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,260 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 67,756 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-25 11:58:03
合計ジャッジ時間 1,270 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	char tmp;
	std::vector<int> input;
	while (std::cin >> tmp) {
		input.push_back(tmp-'0');
	}
	std::vector<int> max_checker(input);
	while(true) {
		for (auto it = max_checker.begin() + 1; it != max_checker.end(); ++it) {
			if (max_checker.front() < *it) {
				goto CHECK;
			}
		}
		max_checker.erase(max_checker.begin());
		if (max_checker.empty()) goto OUTPUT;
	}
CHECK:///////////////////////////////////////goto CHECK
	std::sort(max_checker.begin(), max_checker.end());
	std::reverse(max_checker.begin(), max_checker.end());
	for (auto it = max_checker.rbegin(); it != max_checker.rend(); ++it) {
		if (*it == max_checker.front()) {
			for (auto it2 = max_checker.begin(); it2 != max_checker.end(); ++it2) {
				if (*it2 != max_checker.front() || *it == *it2) {
					std::swap(*it, *it2);
					auto it3 = input.rbegin();
					for (auto it4 = max_checker.rbegin(); it4 != max_checker.rend(); ++it4, ++it3) {
						*it3 = *it4;
					}
					goto OUTPUT;
				}
			}
		}
	}
OUTPUT:////////////////////////////////////////goto OUTPUT
	for (auto it : input) {
		std::cout << it;
	}
	std::cout << "\n";

	return 0;
}
0