結果

問題 No.539 インクリメント
ユーザー mogurockermogurocker
提出日時 2017-10-15 15:49:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 1,786 ms
コンパイル使用メモリ 166,748 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 21:31:08
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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);
		
		int x = atoi(sub.c_str());
		string from = to_string(x);
		x++;
		string to = to_string(x);
		if (to.size() > from.size() && sub[0] != '0') {
			ans[i] = s.substr(0, l) + to + s.substr(r+1);
		}
		else {
			string ret(sub.size()-to.size(), '0');
			ret += to;
			ans[i] = s.substr(0, l) + ret + s.substr(r+1);
		}
	}
	FOR(i, t) cout << ans[i] << endl;
	return 0;
}
0