結果

問題 No.539 インクリメント
ユーザー mogurockermogurocker
提出日時 2017-10-15 16:16:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,087 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 164,820 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 21:31:48
合計ジャッジ時間 2,154 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int t;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> t;
	cin.ignore();
	vector<string> ans(t);
	FOR(i, t) {
		string s;
		getline(cin, s);

		int n = s.size(), l = -1, r = -1, pos = n-1;
		while (pos >= 0 && !(s[pos] >= '0' && s[pos] <= '9')) pos--;
		r = pos;
		if (r == -1) {
			ans[i] = s;
			continue;
		}
		while (pos >= 0 && s[pos] >= '0' && s[pos] <= '9') pos--;
		l = pos + 1;
		string sub = s.substr(l, r-l+1);

		string ret;
		int cur, inc = 1;
		for (int j = sub.size()-1; j >= 0; j--) {
			cur = sub[j]-'0'+inc;
			if (cur == 10) {
				sub[j] = '0';
				inc = 1;
			}
			else {
				sub[j] = (char)('0'+cur);
				inc = 0;
			}
		}
		ret = (inc == 1 ? "1"+sub : sub);
		ans[i] = s.substr(0, l) + ret + s.substr(r+1);		
	}
	FOR(i, t) cout << ans[i] << endl;
	return 0;
}
0