結果

問題 No.539 インクリメント
ユーザー ngtkanangtkana
提出日時 2020-04-04 22:53:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,056 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 201,716 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 06:15:45
合計ジャッジ時間 3,381 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using lubl=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    auto increment=[&](std::string s){
        lint n=s.length();
        for(lint i=n-1;i>=0;i--){
            if(s.at(i)!='9'){
                s.at(i)++;
                for(i++;i<n;i++)s.at(i)='0';
                return s;
            }
        }
        std::fill(ALL(s),'0');
        s.insert(s.begin(),'1');
        return s;
    };
    lint q;std::cin>>q;
    std::string _;std::getline(std::cin,_);
    while(q--){
        std::string s;std::getline(std::cin,s);
        lint n=s.length();
        lint r=n;
        for(;r&&!std::isdigit(s.at(r-1));r--);
        if(r==0){
            std::cout<<s<<'\n';
            continue;
        }
        lint l=r;
        for(;l&&std::isdigit(s.at(l-1));l--);
        std::cout<<s.substr(0,l)+increment(s.substr(l,r-l))+s.substr(r,n-r)<<'\n';
    }
}
0