結果

問題 No.539 インクリメント
ユーザー Mcpu3Mcpu3
提出日時 2019-06-22 17:33:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 646 ms
コンパイル使用メモリ 68,644 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 03:00:03
合計ジャッジ時間 2,312 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
	int T, j, k;
	cin >> T;
	string S;
	getline(cin, S);
	for (int i = 0; i < T; ++i) {
		getline(cin, S);
		j = S.find_last_of("0123456789");
		if (j == string::npos) cout << S;
		else {
			string a;
			for (k = j; k >= 0; --k) {
				if ('0' > S[k] || '9' < S[k]) break;
				a += S[k];
			}
			S.erase(1 + k, j - k);
			for (j = 0; j < a.size(); ++j) {
				if ('9' == a[j]) a[j] = '0';
				else {
					++a[j];
					break;
				}
			}
			if (a.size() == j) a += '1';
			reverse(a.begin(), a.end());
			S.insert(1 + k, a);
			cout << S;
		}
		cout << endl;
	}
}
0