結果
問題 | No.539 インクリメント |
ユーザー |
👑 ![]() |
提出日時 | 2017-06-30 23:03:52 |
言語 | C++14 (gcc 12.2.0 + boost 1.81.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 1,874 bytes |
コンパイル時間 | 1,611 ms |
コンパイル使用メモリ | 169,040 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-07-27 20:12:00 |
合計ジャッジ時間 | 2,585 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 8 ms
4,376 KB |
testcase_02 | AC | 13 ms
4,380 KB |
testcase_03 | AC | 13 ms
4,380 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string S; string incriment(string s) { int d = 1; int n = s.length(); rep(i, 0, n) { int c = s[n - 1 - i] - '0' + d; d = c / 10; c = c % 10; s[n - 1 - i] = char('0' + c); } if (0 < d) s = char('0' + d) + s; return s; } void solve() { getline(cin, S); pair<int, int> p = {-1, -1}; rep(L, 0, S.length()) if('0' <= S[L] && S[L] <= '9') { int R = L + 1; while ('0' <= S[R] && S[R] <= '9') R++; p = { L, R - 1 }; L = R - 1; } if (p.first < 0) { printf("%s\n", S.c_str()); return; } string A = S.substr(0, p.first); string B = S.substr(p.first, p.second - p.first + 1); string C = S.substr(p.second + 1); B = incriment(B); printf("%s%s%s\n", A.c_str(), B.c_str(), C.c_str()); } //--------------------------------------------------------------------------------------------------- void _main() { int T; cin >> T; string S; getline(cin, S); rep(i, 0, T) solve(); }