結果

問題 No.539 インクリメント
ユーザー CELICACELICA
提出日時 2020-09-17 08:31:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 915 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 169,888 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2023-09-04 07:04:23
合計ジャッジ時間 2,733 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;

const string TARGET_NO = "0539";

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	cin >> t;
	cin.ignore();

	vector<string> vs(t);
	for (auto&& it : vs)
		getline(cin, it);

	stringstream ss;
	for (auto&& v : vs)
	{
		bool f{ false };
		char carry{ 1 };
		auto it = v.rbegin();

		while (carry && it != v.rend())
		{
			if (*it >= '0' && *it <= '8')
			{
				++(*it);
				f = true;
				carry = 0;
			}
			else if (*it == '9')
			{
				*it = '0';

				if (it + 1 == v.rend())
				{
					v = "1" + v;
					break;
				}
				else
					f = true;
			}
			else
			{
				if (f)
				{
					v.insert(v.rend() - it, string("1"));
					break;
				}
			}

			++it;
		}

		ss << v << "\n";
	}

	cout << ss.str();

	return 0;
}
0