結果

問題 No.539 インクリメント
ユーザー teketeke5000teketeke5000
提出日時 2017-10-24 20:08:01
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,289 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 163,552 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 13:11:17
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 43 ms
6,940 KB
testcase_02 RE -
testcase_03 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:41:20: warning: ‘isZero’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         if (isZero && isNine) st--;
      |             ~~~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(ll i=(a); i<(ll)(n); i++)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(v) (v).begin(), (v).end()

int main(void) {
    int T;
    int level;
    cin >> T;
    string strs[T];
    cin.ignore();
    for (int i=0; i<T; i++) {
        string str;
        bool line = false;
        bool isZero;
        bool isNine;
        int st=0,en=0;
        getline(cin, str);
        for (int j=str.size()-1; j>=0; j--) {
            if (!line) {
                if (isdigit(str[j])) {
                    en = j;
                    line = !line;
                }
            } else {
                if (!isdigit(str[j]) || str[j] == '0') {
                    isZero = str[j] == '0';
                    st = j+1;
                    break;
                }
            }
        }
        if (!line)  {
            strs[i] = str;
            continue;
        }
        isNine = str.front() == '9';
        level = stoi(str.substr(st, en - st + 1)) + 1;
        if (isZero && isNine) st--;
        strs[i] = str.substr(0, st) + to_string(level) + str.substr(en+1, str.size() - 1);
    }
    for (int i=0; i<T; i++) cout << strs[i] << endl;
    return 0;
}
0