結果

問題 No.539 インクリメント
ユーザー んんんんんん
提出日時 2022-12-23 11:21:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 2,252 ms
コンパイル使用メモリ 205,824 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:14:04
合計ジャッジ時間 3,101 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

string S;

void solve() {
    getline(cin, S);

    bool f = false;
    for (auto c : S) f |= isdigit(c);

    if (!f) {
        cout << S << endl;
        return;
    }

    bool kr = true;
    for (int i = S.size()-1; i >= 0; i--) {
        char c = S[i];
        if (isdigit(c)) {
            while (1) {
                char &n = S[i];
                if (isdigit(n) && kr) n++;
                if (n == 10 + '0') {
                    n = '0';
                } else if (isdigit(n)) {
                    kr = false;
                }
                i--;

                if (i == -1 || !isdigit(n)) {
                    if (kr) {
                        if (i == -1) S = S.substr(0, i+1) + '1' + S.substr(i+1);
                        else S = S.substr(0, i+2) + '1' + S.substr(i+2);
                    }
                    break;
                };
            }
            break;
        }
    }

    cout << S << endl;
}

int main() {
    int T;
    cin >> T;
    getline(cin, S);

    while (T--) {
        solve();
    }
}
0