結果

問題 No.539 インクリメント
ユーザー 193s193s
提出日時 2017-06-30 22:53:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,298 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 83,504 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-15 06:51:12
合計ジャッジ時間 1,368 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int T;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> T;
  string s;
  getline(cin, s);
  rep(_, T) {
    getline(cin, s);
    int offset = -1;
    rep(i, s.length()) {
      char c = s[i];
      if (c >= '0' && c <= '9') offset = i;
    }
    if (offset == -1) {
      cout << s << "\n";
      continue;
    }
    bool ok = false;
    while (offset >= 0 && s[offset] >= '0' && s[offset] <= '9') {
      if (s[offset] != '9') {
        s[offset]++;
        ok = true;
        break;
      }
      s[offset] = '0';
      offset--;
    }
    string o = "";
    if (ok) o = s;
    else {
      rep(i, offset+1) {
        if (i >= s.length()) continue;
        o += s[i];
      }
      o += '1';
      for (int i=offset+1; i<s.length(); i++) o += s[i];
    }
    cout << o << "\n";
  }
  return 0;
}
0