結果

問題 No.539 インクリメント
ユーザー t98slidert98slider
提出日時 2023-07-10 23:34:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 165,852 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-10 01:26:44
合計ジャッジ時間 2,564 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    string s, t, s2;
    getline(cin, s);
    T = stoi(s);
    while(T--){
        string s, t, s2;
        getline(cin, s);
        while(!s.empty() && !isdigit(s.back())){
            s2 += s.back();
            s.pop_back();
        }
        while(!s.empty() && isdigit(s.back())){
            t += s.back();
            s.pop_back();
        }
        if(!t.empty()){
            t[0]++;
            for(int i = 0; i < t.size(); i++){
                if(t[i] >= '0' + 10){
                    t[i] -= 10;
                    if(t.size() == i + 1) t += '1';
                    else t[i + 1]++;
                }
            }
        }
        reverse(s2.begin(), s2.end());
        reverse(t.begin(), t.end());
        cout << s << t << s2 << '\n';
    }
}
0