結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
かに
|
| 提出日時 | 2017-07-05 22:29:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,345 bytes |
| コンパイル時間 | 2,272 ms |
| コンパイル使用メモリ | 201,464 KB |
| 最終ジャッジ日時 | 2025-01-05 01:12:53 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 1 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:41: warning: ‘pos’ may be used uninitialized [-Wmaybe-uninitialized]
65 | string ans = v[i].substr(0, pos) + num;
| ~~~~~~~~~~~^~~~~~~~
main.cpp:26:21: note: ‘pos’ was declared here
26 | int pos;
| ^~~
ソースコード
#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') {
num[j] = '0';
j--;
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 = v[i].substr(0, pos) + num;
if (pos + numlen != v[i].length()) {
ans = ans + v[i].substr(pos + numlen, v[i].length() - (pos + numlen));
}
P(ans);
}
}
かに