結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  mogurocker | 
| 提出日時 | 2017-10-15 16:16:01 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 1,087 bytes | 
| コンパイル時間 | 1,101 ms | 
| コンパイル使用メモリ | 165,648 KB | 
| 実行使用メモリ | 5,632 KB | 
| 最終ジャッジ日時 | 2024-11-17 17:46:26 | 
| 合計ジャッジ時間 | 1,800 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#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;
}
            
            
            
        