結果

問題 No.539 インクリメント
ユーザー koba-e964koba-e964
提出日時 2017-07-01 00:24:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 842 ms
コンパイル使用メモリ 91,852 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:23:57
合計ジャッジ時間 1,503 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

string increment(string s) {
  int carry = 1;
  int n = s.length();
  for (int i = n - 1; i >= 0; --i) {
    s[i] += carry;
    carry = 0;
    if (s[i] > '9') {
      s[i] = '0';
      carry = 1;
    }
  }
  if (carry) {
    return '1' + s;
  }
  return s;
}


string calc(const string &s) {
  int start = -1;
  int end = -1;
  int n = s.length();
  bool prev = false;
  REP(i, 0, n) {
    if (isdigit(s[i])) {
      if (not prev) {
	start = i;
      }
      prev = true;
      end = i + 1;
    } else {
      prev = false;
    }
  }
  if (start < 0) {
    return s;
  }
  // increment [start, end)
  return s.substr(0, start) + increment(s.substr(start, end - start))
    + s.substr(end);
}

int main(void){
  int t;
  string first;
  getline(cin, first);
  stringstream ss(first);
  ss >> t;
  REP(i, 0, t) {
    string s;
    getline(cin, s);
    cout << calc(s) << endl;
  }
}
0