結果

問題 No.539 インクリメント
ユーザー かにかに
提出日時 2017-07-06 01:01:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,311 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 201,636 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-15 18:26:26
合計ジャッジ時間 5,550 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:3:34: warning: 'pos' may be used uninitialized [-Wmaybe-uninitialized]
    3 | #define rep(a,b) for(int a = 0;a < b;a++)
      |                                  ^
main.cpp:64:17: note: in expansion of macro 'rep'
   64 |                 rep(j, pos) {
      |                 ^~~
main.cpp:26:21: note: 'pos' was declared here
   26 |                 int pos;
      |                     ^~~

ソースコード

diff #

#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
unsigned long long str_to_int(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

int main() {
	int n;
	cin >> n; cin.ignore();
	vector<string> v(n);
	rep(i, n) {
		 getline(cin,v[i]);
	}
	rep(i, n) {
		int pos;
		string num = "";
		rep(j, v[i].length()) {
			if (v[i][j] >= '0' and v[i][j] <= '9') {
				num = "";
				pos = j;
				while (v[i][j] >= '0' and v[i][j] <= '9') {
					num = num + v[i][j];
					j++;
					if (j == v[i].length()) {
						break;
					}
				}
			}
		}
		int numlen = num.length();
		if (num == "") {
			P(v[i]);
			continue;
		}
		int j = num.length() - 1;
		if (num[j] == '9') {
			while (num[j] == '9') {
				num[j] = '0';
				j--;
				if (j < 0) {
					num = '1' + num;
					break;
				}
			}
			if (j >= 0) {
				num[j] = num[j] + 1;
			}
		}
		else {
			num[j] = num[j] + 1;
		}
		string ans = "";
		rep(j, pos) {
			ans = ans + v[i][j];
		}
		ans = ans + num;
		REP(j, pos + numlen, v[i].length()) {
			ans = ans + v[i][j];
		}
		P(ans);
	}
}
0