結果

問題 No.539 インクリメント
ユーザー hiyokko2hiyokko2
提出日時 2017-06-30 23:08:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,510 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 163,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 06:59:58
合計ジャッジ時間 2,082 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;



signed main()
{
    int T;
    string S;

    cin >> T;
    cin.ignore();
    REP(i,T) {
        //cin >> S;
        getline(cin, S);
        reverse(S.begin(), S.end());
        bool hit = false;
        REP(j,S.length()) {
            if ('0' <= S[j] && S[j] <= '8') {
                S[j] += 1;
                reverse(S.begin(), S.end());
                cout << S << endl;
                hit = true;
                break;
            } else if (S[j] == '9') {
                //cout << "AAAAAa" << endl;
                while (S[j] == '9') {
                    S[j] = '0';
                    j++;

                }
                //cout <<"TEST" << S << endl;
                if ('0' <= S[j] && S[j] <= '8') {
                    S[j]++;
                    reverse(S.begin(), S.end());
                    cout << S << endl;
                    hit = true;
                    break;
                } else {
                    string ans = S.substr(0, j) + '1' + S.substr(j);
                    reverse(ans.begin(), ans.end());
                    cout << ans << endl;
                    hit = true;
                    break;
                }
            }
        }
        if (!hit) {
            reverse(S.begin(), S.end());
            cout << S << endl;
        }
    }

}
0