結果
問題 | No.539 インクリメント |
ユーザー |
|
提出日時 | 2022-12-23 11:21:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,085 bytes |
コンパイル時間 | 1,877 ms |
コンパイル使用メモリ | 198,680 KB |
最終ジャッジ日時 | 2025-02-09 19:02:58 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>using namespace std;string S;void solve() {getline(cin, S);bool f = false;for (auto c : S) f |= isdigit(c);if (!f) {cout << S << endl;return;}bool kr = true;for (int i = S.size()-1; i >= 0; i--) {char c = S[i];if (isdigit(c)) {while (1) {char &n = S[i];if (isdigit(n) && kr) n++;if (n == 10 + '0') {n = '0';} else if (isdigit(n)) {kr = false;}i--;if (i == -1 || !isdigit(n)) {if (kr) {if (i == -1) S = S.substr(0, i+1) + '1' + S.substr(i+1);else S = S.substr(0, i+2) + '1' + S.substr(i+2);}break;};}break;}}cout << S << endl;}int main() {int T;cin >> T;getline(cin, S);while (T--) {solve();}}