結果

問題 No.539 インクリメント
ユーザー どららどらら
提出日時 2017-06-30 23:42:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 1,627 ms
コンパイル使用メモリ 165,972 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:11:39
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

void inc(string S){
  bool leading_zero = false;
  if(S[0]=='0') leading_zero = true;

  int up = 1;
  for(int i=S.size()-1; i>=0; i--){
    int v = up + (int)(S[i]-'0');
    up = v/10;
    S[i] = (char)('0' + v%10);
  }
  if(leading_zero){
    cout << S;
  }else{
    if(up > 0) cout << up << S;
    else cout << S;
  }
}

void solve(const string& S){
  int s = -1, t = -1;
  for(int i=S.size()-1; i>=0; i--){
    if('0'<=S[i] && S[i]<='9'){
      if(t == -1){
        t = i;
        s = i;
      }else{
        s = i;
      }
    }else{
      if(t == -1) continue;
      else break;
    }
  }

  if(s == -1){
    cout << S << endl;
  }else{
    cout << S.substr(0,s);
    inc(S.substr(s,t+1-s));
    cout << S.substr(t+1) << endl;
  }
}

int main(){
  int T;
  cin >> T;
  string S;
  getline(cin, S);
  rep(t,T){
    getline(cin, S);
    solve(S);
  }
  
  return 0;
}
0