結果

問題 No.539 インクリメント
ユーザー treeonetreeone
提出日時 2017-06-30 22:57:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 1,379 ms
コンパイル使用メモリ 164,236 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 06:53:32
合計ジャッジ時間 2,222 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 41 ms
6,944 KB
testcase_02 AC 45 ms
6,940 KB
testcase_03 AC 45 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

string solve(string s,string t = "1"){
	if(s.size()<t.size()) swap(s,t);
	for(int i=s.size()-1,j=t.size()-1;i>=0;i--,j--){
		if(j>=0) s[i]+=t[j]-'0';
		if(s[i]>'9'){
			s[i]-=10;
			if(i==0) s='1'+s;
			else s[i-1]++;
		}
	}
	return s;
}

signed main(){
    int t;
    cin >> t;
    getchar();
    rep(i, 0, t){
        string s;
        getline(cin, s);
        string t;
        int r = -1, l = -1;
        bool f = false;
        repb(i, s.size() - 1, 0){
            if('0' <= s[i] && s[i] <= '9'){
                if(f == true){
                    l = i;
                }else if(f == false){
                    r = i;
                    l = i;
                    f = true;
                }
            }else if(f == true){
                break;
            }
        }
        if(l == -1 && r == -1){
            cout << s << endl;
            continue;
        }
        // cout << l << " " << r << endl;
        t = s.substr(l, r - l + 1);
        // cout << t << endl;
        t = solve(t);
        // cout  << t << endl;
        s = s.substr(0, l) + t + s.substr(r + 1);
        cout << s << endl;
    }
}
0