結果
| 問題 |
No.539 インクリメント
|
| コンテスト | |
| ユーザー |
かに
|
| 提出日時 | 2017-07-06 01:01:41 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,311 bytes |
| コンパイル時間 | 2,503 ms |
| コンパイル使用メモリ | 201,808 KB |
| 最終ジャッジ日時 | 2025-01-05 01:13:39 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | TLE * 3 |
コンパイルメッセージ
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;
| ^~~
ソースコード
#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);
}
}
かに