結果

問題 No.539 インクリメント
ユーザー sekiya9311sekiya9311
提出日時 2017-06-30 23:44:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 164,744 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 07:11:50
合計ジャッジ時間 2,445 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 42 ms
6,944 KB
testcase_02 AC 41 ms
6,944 KB
testcase_03 AC 43 ms
6,940 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