結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  peroon | 
| 提出日時 | 2019-06-24 06:22:45 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 97 ms / 2,000 ms | 
| コード長 | 2,301 bytes | 
| コンパイル時間 | 2,173 ms | 
| コンパイル使用メモリ | 174,996 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-12-31 06:29:36 | 
| 合計ジャッジ時間 | 3,604 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
string zero_padding(string s, ll len){
    ll diff = len - s.size();
    stringstream ss;
    FOR(i, 0, diff){
        ss << '0';
    }
    ss << s;
    return ss.str();
}
ll ctoi(char c){
    ll v = c - '0';
    return v;
}
string string_add(string s, string t){
    ll L = max(s.size(), t.size());
    s = zero_padding(s, L);
    t = zero_padding(t, L);
    stringstream ss;
    ll carry = 0; // 繰り上がり
    for(int i=L-1; i>=0; i--){
        ll v = ctoi(s[i]) + ctoi(t[i]) + carry;
        if(v>9){
            carry = 1;
            v = v%10;
        }else{
            carry = 0;
        }
        ss << v;
    }
    if(carry==1){
        ss << 1;
    }
    string ret = ss.str();
    reverse(ALL(ret));
    return ret;
}
void string_add_test(){
    auto a = string_add("111", "999");
    pn(a);
    auto b = string_add("1234", "10");
    pn(b);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // input
    ll T;
    cin >> T;
    string dustbox;
    getline(cin, dustbox);
    
    while(T--){
        string s; 
        //cin >> s;
        getline(cin, s);
        ll L = s.size();
        // head -- num -- tail
        ll i;
        for(i=L-1; i>=0; i--){
            if(isdigit(s[i])){
                break;
            }
        }
        ll tail_i = i+1;
        // if number nothing
        if(tail_i==0){
            p(s);
            continue;
        }
        for(i=tail_i-1; i>=0; i--){
            if(!isdigit(s[i])) break;
        }
        ll num_i = i+1;
        string head = s.substr(0, num_i);
        string num = s.substr(num_i, tail_i-num_i);
        string tail = s.substr(tail_i);
        stringstream ss;
        ss << head;
        ss << string_add(num, "1");
        ss << tail;
        string ans = ss.str();
        p(ans);
    }
    
    return 0;
}
            
            
            
        