結果

問題 No.539 インクリメント
ユーザー tnakao0123tnakao0123
提出日時 2017-07-08 14:28:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,010 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 84,884 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 06:25:15
合計ジャッジ時間 2,091 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 539.cc: No.539 インクリメント - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;
  while (cin.get() != '\n');

  while (tn--) {
    string s;
    getline(cin, s);

    int p = s.size() - 1;
    while (p >= 0 && (s[p] < '0' || s[p] > '9')) p--;

    if (p < 0) {
      puts(s.c_str());
      continue;
    }

    bool co = true;
    while (co && p >= 0 && s[p] >= '0' && s[p] <= '9') {
      s[p]++;
      if (s[p] > '9') s[p] = '0';
      else co = false;
      p--;
    }

    if (co) s.insert(p + 1, 1, '1');

    puts(s.c_str());
  }

  return 0;
}
0