結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2018-09-09 17:25:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 1,346 bytes |
コンパイル時間 | 1,467 ms |
コンパイル使用メモリ | 170,772 KB |
実行使用メモリ | 6,816 KB |
最終ジャッジ日時 | 2024-12-23 16:04:28 |
合計ジャッジ時間 | 3,185 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;using int64 = long long;using uint64 = unsigned long long;pair<int, int> extractLastNumber(string s){reverse(s.begin(), s.end());int numBegin = 0;while (numBegin < s.size() and !isdigit(s[numBegin])){numBegin++;}int numEnd = numBegin;while (numEnd < s.size() and isdigit(s[numEnd])){numEnd++;}return {s.size() - numEnd, s.size() - numBegin};}string increment(string digits){if (digits.empty())return "";string res = "";int carry = 1;for (int i = digits.size() - 1; i >= 0; i--){int d = (digits[i] - '0') + carry;carry = d / 10;res.push_back('0' + (d % 10));}if (carry > 0)res.push_back('1');reverse(res.begin(), res.end());return res;}int main(){cin.tie(nullptr);ios::sync_with_stdio(false);int T;cin >> T;cin.ignore();for (int i = 0; i < T; i++){string s;getline(cin, s);auto indices = extractLastNumber(s);int len = indices.second - indices.first;cout << s.substr(0, indices.first);cout << increment(s.substr(indices.first, len));cout << s.substr(indices.second, s.size() - indices.second) << endl;}return 0;}