結果

問題 No.539 インクリメント
ユーザー tottoripapertottoripaper
提出日時 2017-08-04 00:44:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,500 bytes
コンパイル時間 1,419 ms
コンパイル使用メモリ 163,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 01:48:27
合計ジャッジ時間 2,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 25 ms
5,376 KB
testcase_02 AC 22 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int N;
    std::cin >> N;

    std::cin.ignore();
    
    for(int _=0;_<N;++_){        
        std::string S;
        std::getline(std::cin, S);
        
        int first = -1, end = 0;
        for(int i=0,j=0;i<S.size();i=j){
            while(j < S.size() && !std::isdigit(S[j])){
                ++j;
            }

            if(j == S.size()){break;}

            first = j;
            while(j < S.size() && std::isdigit(S[j])){
                ++j;
            }

            end = j;
        }

        if(first == -1){
            std::cout << S << std::endl;
            return 0;
        }

        for(int i=0;i<first;++i){
            std::cout << S[i];
        }

        S[end-1] += 1;
    
        bool carry = false;
        for(int i=end-1;i>=first;--i){
            if(S[i] > '9'){
                if(i == first){carry = true;}
                else{S[i-1] += 1;}
                S[i] -= 10;
            }else{
                break;
            }
        }

        if(carry){std::cout << 1;}

        for(int i=first;i<S.size();++i){
            std::cout << S[i];
        }

        std::cout << std::endl;
    }
}
0