結果

問題 No.256 桁の数字を入れ替え (2)
ユーザー CrossLunaCrossLuna
提出日時 2015-07-31 22:40:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 656 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 68,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 22:52:27
合計ジャッジ時間 1,075 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>


using namespace std;

int main(){
    int N;
    string S;
    cin >> S;

    vector<char> v;
    for(int i = 0; i< S.size(); i++)
        v.push_back(S[i]);


    auto it = max_element(v.begin(), v.end());
    swap(*it, v[0]);
    if(v.size() > 1){
        auto jt = max_element(v.begin()+1, v.end());
        swap(*jt, v[1]);
        if(it > jt) swap(it, jt);
        if(*it < *jt) swap(*it, *jt);
    }

    for(int i=0 ;i < v.size(); i++)
        cout << v[i];

    cout << endl;
    
    return 0;
}
0