結果

問題 No.539 インクリメント
ユーザー kotamanegikotamanegi
提出日時 2017-06-30 23:33:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,674 bytes
コンパイル時間 831 ms
コンパイル使用メモリ 96,864 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:09:28
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int t;
	cin >> t;
	string alpha;
	getline(cin, alpha);
	REP(test_case, t) {
		string s;
		getline(cin, s);
		string change;
		int touch = -1;
		for (int i = s.length() - 1;i >= 0;--i) {
			if (change.length() != 0) {
				if (s[i] >= '0'&&s[i] <= '9') {
					touch = i;
					change.push_back(s[i]);
				}
				else {
					break;
				}
			}	else {
				if (s[i] >= '0' && s[i] <= '9') {
					touch = i;
					change.push_back(s[i]);
				}
			}
		}
		if (touch == -1) {
			cout << s << endl;
			goto ok;
		}
		reverse(change.begin(), change.end());
		for (int i = change.length() - 1;i >= 0;--i) {
			if (change[i] == '9') {
				change[i] = '0';
				if (i == 0) change = "1" + change;
			}
			else {
				change[i] += 1;
				break;
			}
		}
		for (int i = 0;i < touch;++i) {
			cout << s[i];
		}
		cout << change;
		for (int i = s.length() - 1;i >= 0;--i) {
			if (s[i] >= '0' && s[i] <= '9') {
				for (int q = i + 1;q < s.length();++q) {
					cout << s[q];
				}
				break;
			}
		}
		cout << endl;
	ok:;
	}
	return 0;
}
0