結果
問題 | No.539 インクリメント |
ユーザー | startcpp |
提出日時 | 2017-07-01 00:21:19 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 909 bytes |
コンパイル時間 | 577 ms |
コンパイル使用メモリ | 65,076 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-15 07:23:23 |
合計ジャッジ時間 | 1,389 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 46 ms
6,940 KB |
testcase_02 | AC | 54 ms
6,944 KB |
testcase_03 | AC | 53 ms
6,944 KB |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <fstream> using namespace std; int t; string s; string reverse(string s) { int l = 0, r = s.length() - 1; while (l < r) { swap(s[l], s[r]); l++; r--; } return s; } string increse(string s) { if (s.length() == 0) return s; int i, j; string t, u; for (i = s.length() - 1; i >= 0; i--) { if (s[i] != '9') break; u += '0'; } for (j = 0; j <= i; j++) t += s[j]; if (i < 0) { return "1" + t + u; } t[i]++; return t + u; } int main() { cin >> t; getline(cin, s); while (t--) { getline(cin, s); int i; string a, b, c; for (i = s.length() - 1; i >= 0; i--) { if ('0' <= s[i] && s[i] <= '9') break; a += s[i]; } for (; i >= 0; i--) { if (!('0' <= s[i] && s[i] <= '9')) break; b += s[i]; } for (; i >= 0; i--) { c += s[i]; } cout << reverse(c) + increse(reverse(b)) + reverse(a) << endl; } return 0; }