結果

問題 No.539 インクリメント
ユーザー kurenai3110kurenai3110
提出日時 2017-06-30 22:40:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 67,736 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 06:44:56
合計ジャッジ時間 1,346 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
using namespace std;

int main()
{
	int n; cin >> n;
	cin.ignore();

	for (int i = 0; i < n; i++) {
		string s; getline(cin, s);

		bool up = false;

		for (int j = s.size() - 1; j >= 0; j--) {
			if (up) {
				if (s[j] >= '0' && s[j] < '9') {
					s[j]++;
					up = false;
					break;
				}
				else if(s[j] == '9'){
					s[j] = '0';
					up = true;
				}
				else {
					s.insert(s.begin()+j+1,'1');
					up = false;
					break;
				}
			}
			else {
				if (s[j] >= '0' && s[j] < '9') {
					s[j]++;
					up = false;
					break;
				}
				else if (s[j] == '9') {
					s[j] = '0';
					up = true;
				}
			}
		}

		if (up)s.insert(s.begin(), '1');

		cout << s << endl;
	}

	return 0;
}
0