結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-11-02 17:13:07 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 41 ms / 2,000 ms | 
| コード長 | 1,230 bytes | 
| コンパイル時間 | 875 ms | 
| コンパイル使用メモリ | 96,876 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-22 06:23:17 | 
| 合計ジャッジ時間 | 1,765 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#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, b3 = false;
		for (int j = n - 1; j >= 0; j--) {
			if (isdigit(s[j])) {
				b3 = true;
				if (s[j] == '9') {
					break;
				}
				s[j]++;
				cout << s << endl;
				b = true;
				break;
			}
		}
		if (!b3) {
			cout << s << endl;
			continue;
		}
		bool b1 = false;
		if (!b) {
			bool b2 = false;
			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;
					b2 = true;
					break;
				}
				else if (b1 && s[j] >= '0' && s[j] <= '8') {
					s[j]++;
					cout << s << endl;
					b2 = true;
					break;
				}
			}
			if (!b2) {
				s = '1' + s;
				cout << s << endl;
			}
		}
	}
	return 0;
}
            
            
            
        