結果

問題 No.539 インクリメント
ユーザー rankBBNTrankBBNT
提出日時 2017-07-04 22:37:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 904 bytes
コンパイル時間 512 ms
コンパイル使用メモリ 58,380 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-15 16:20:43
合計ジャッジ時間 1,177 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;

int main(void){
    int T;
    cin >> T;
    
    for (int i=0; i<=T; i++) {
        string s;
        std::getline(cin, s);

        int dpos;
        for (dpos=s.length()-1; dpos>=0; dpos--) {
            if (isdigit(s[dpos])) break;
        }
        if (dpos==-1) {
            cout << s << endl;
            continue;
        }
        
        if (s[dpos]!='9') {
            s[dpos]++;
            cout << s << endl;
            continue;
        }
        
        while (s[dpos]=='9') {
            s[dpos] = '0';
            if (dpos==0 || !isdigit(s[dpos-1])) {
                cout << s.substr(0, dpos) << "1" << s.substr(dpos) << endl;
            } else if (s[dpos-1]!='9') {
                s[dpos-1]++;
                cout << s << endl;
            }
            dpos--;
        }
    }
}
0