結果
問題 | No.539 インクリメント |
ユーザー |
|
提出日時 | 2020-09-16 17:04:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 59 ms / 2,000 ms |
コード長 | 1,072 bytes |
コンパイル時間 | 2,996 ms |
コンパイル使用メモリ | 198,848 KB |
最終ジャッジ日時 | 2025-01-14 15:15:24 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,n) for(int i=0; i<(int)(n); i++)#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)#define ALL(x) (x).begin(), (x).end()const double PI = acos(-1);string solve() {string s;getline(cin, s);vector<string> vs;for (int i = 0; i < s.length(); ) {int j = i;while (j < s.length() && isdigit(s[j]) == isdigit(s[i]))++j;vs.push_back(s.substr(i, j-i));i = j;}int p = -1;for (int i = vs.size()-1; i >= 0; i--) {if (isdigit(vs[i][0])) {p = i;break;}}if (p == -1) return s;string &x = vs[p];x.back()++;for (int i = x.length()-1; i > 0; i--) {if (x[i] > '9') {x[i] = '0';x[i-1]++;}}if (x[0] > '9') {x[0] = '0';x = "1" + x;}string ret;for (string x: vs)ret += x;return ret;}int main() {ios_base::sync_with_stdio(0);cin.tie(0);int T;cin >> T;string blank;getline(cin, blank);while (T--) {cout << solve() << endl;}return 0;}