結果

問題 No.539 インクリメント
ユーザー sekiya9311sekiya9311
提出日時 2017-06-30 23:44:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 1,473 ms
コンパイル使用メモリ 165,556 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-27 20:29:52
合計ジャッジ時間 2,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

void solve() {
	string s;
	getline(cin, s);
	reverse(s.begin(), s.end());
	bool f = false;
	for (int i = 0; i < s.size(); i++) {
	    if (isdigit(s[i])) {
	  		if (s[i] == '9') {
				s[i] = '0';
				f = true;
			} else {
				s[i]++;
				f = false;
				break;
			}
	    } else if (f) {
			s.insert(i, "1");
			f = false;
			break;
		}
	}
	if (f) s += "1";
	reverse(s.begin(), s.end());
	cout << s << endl;
}

int main() {
	int T;
	cin >> T;
	cin.ignore();
	while (T--) {
	  solve();
	}
}
0