結果

問題 No.539 インクリメント
ユーザー conankunconankun
提出日時 2017-10-19 23:54:00
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 969 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 53,556 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-08-13 12:45:57
合計ジャッジ時間 1,241 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    cin.ignore();

    string strs[20];

    for (int i = 0; i < T; i++) {
        string str;
        getline(cin, str);
        int strLen = str.length();
        bool preNine = false;
        for (int j = strLen - 1; j >= 0; j--) {
            if (isdigit(str[j])) {
                int num = str[j] - '0';
                preNine = num == 9;
                str[j] = '0' + (preNine ? 0 : ++num);
                if (!preNine) break;
            }
            else if (preNine) {
                str.insert(j + 1, "1");
                preNine = false;
                break;
            }
        }

        if (preNine) str.insert(0, "1");

        strs[i] = str;
    }

    for (int i = 0; i < T; i++) {
        cout << strs[i] << "\n";
    }

    int a;
    cin >> a;
}
0