結果

問題 No.539 インクリメント
ユーザー 夜
提出日時 2020-11-02 17:04:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,152 bytes
コンパイル時間 827 ms
コンパイル使用メモリ 95,568 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 12:01:07
合計ジャッジ時間 2,280 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		string s;
		do {
		getline(cin, s);
		} while (s.size() < 1);
		int n = s.size();
		bool b = false;
		for (int j = n - 1; j >= 0; j--) {
			if (isdigit(s[j])) {
				if (s[j] == '9') {
					break;
				}
				s[j]++;
				cout << s << endl;
				b = true;
				break;
			}
		}
		bool b1 = false;
		if (!b) {
			for (int j = n - 1; j >= 0; j--) {
				if (s[j] == '9') {
					b1 = true;
					s[j] = '0';
				}
				else if (b1 && !isdigit(s[j])) {
					string ans = s.substr(0, j + 1) + '1' + s.substr(j + 1, n - j - 1);
					cout << ans << endl;
					break;
				}
				else if (b1 && s[j] >= '0' && s[j] <= '8') {
					s[j]++;
					cout << s << endl;
					break;
				}
			}
			if (s[0] == '0') {
				s = '1' + s;
				cout << s << endl;
			}
		}
		if (!b && !b1) {
			cout << s << endl;
		}
	}
	return 0;
}
0