結果

問題 No.539 インクリメント
ユーザー face4face4
提出日時 2018-09-02 19:48:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 899 bytes
コンパイル時間 619 ms
コンパイル使用メモリ 69,264 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-10 05:53:10
合計ジャッジ時間 4,414 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cctype>
using namespace std;

int main(){
    int t;
    scanf("%d\n", &t);

    while(t-- > 0){
        string s;
        getline(cin, s);

        string res = "";
        for(int i = s.length()-1; i >= 0; i--){
            if(isdigit(s[i])){
                int carry = 1;
                while(i >= 0 && isdigit(s[i])){
                    int val = carry + (s[i] - '0');
                    carry = val/10;
                    val %= 10;
                    char next = '0' + val;
                    string t{next};
                    res = t + res;
                    i--;
                }
                i++;
                if(carry)   res = "1" + res;
                res = s.substr(0, i) + res;
                break;
            }else{
                res = s.substr(i,1) + res;
            }
        }

        cout << res << endl;
    }

    return 0;
}
0