結果
問題 | No.539 インクリメント |
ユーザー |
![]() |
提出日時 | 2017-07-01 00:21:19 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 909 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 64,820 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-04 22:16:47 |
合計ジャッジ時間 | 1,336 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#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;}