結果
| 問題 | No.539 インクリメント |
| コンテスト | |
| ユーザー |
mogurocker
|
| 提出日時 | 2017-10-15 15:49:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,097 bytes |
| 記録 | |
| コンパイル時間 | 2,064 ms |
| コンパイル使用メモリ | 165,412 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-17 17:45:52 |
| 合計ジャッジ時間 | 1,806 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;
int t;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin >> t;
cin.ignore();
vector<string> ans(t);
FOR(i, t) {
string s;
getline(cin, s);
int n = s.size(), l = -1, r = -1, pos = n-1;
while (pos >= 0 && !(s[pos] >= '0' && s[pos] <= '9')) pos--;
r = pos;
if (r == -1) {
ans[i] = s;
continue;
}
while (pos >= 0 && s[pos] >= '0' && s[pos] <= '9') pos--;
l = pos + 1;
string sub = s.substr(l, r-l+1);
int x = atoi(sub.c_str());
string from = to_string(x);
x++;
string to = to_string(x);
if (to.size() > from.size() && sub[0] != '0') {
ans[i] = s.substr(0, l) + to + s.substr(r+1);
}
else {
string ret(sub.size()-to.size(), '0');
ret += to;
ans[i] = s.substr(0, l) + ret + s.substr(r+1);
}
}
FOR(i, t) cout << ans[i] << endl;
return 0;
}
mogurocker