結果

問題 No.539 インクリメント
ユーザー MisterMister
提出日時 2020-05-29 19:27:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 72,012 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-23 17:08:43
合計ジャッジ時間 1,807 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

void solve() {
    std::string s;
    std::getline(std::cin, s);

    std::string tmp, t;
    while (!s.empty() && !std::isdigit(s.back())) {
        tmp.push_back(s.back());
        s.pop_back();
    }

    while (!s.empty() && std::isdigit(s.back())) {
        t.push_back(s.back());
        s.pop_back();
    }

    if (!t.empty()) {
        int carry = 1;
        for (auto& c : t) {
            c += carry;
            carry = 0;

            if (c > '9') {
                c = '0';
                carry = 1;
            }
        }
        if (carry) t.push_back('1');
    }

    while (!t.empty()) {
        s.push_back(t.back());
        t.pop_back();
    }
    while (!tmp.empty()) {
        s.push_back(tmp.back());
        tmp.pop_back();
    }

    std::cout << s << "\n";
}

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

    int q;
    std::cin >> q;
    {
        std::string tmp;
        std::getline(std::cin, tmp);
    }

    while (q--) solve();

    return 0;
}
0