結果
問題 |
No.39 桁の数字を入れ替え
|
ユーザー |
|
提出日時 | 2016-03-14 18:49:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 602 ms |
コンパイル使用メモリ | 67,004 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-02 06:53:30 |
合計ジャッジ時間 | 1,281 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#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; }