結果
| 問題 | No.539 インクリメント | 
| コンテスト | |
| ユーザー |  ngtkana | 
| 提出日時 | 2020-04-04 22:53:36 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 11 ms / 2,000 ms | 
| コード長 | 1,056 bytes | 
| コンパイル時間 | 2,282 ms | 
| コンパイル使用メモリ | 197,828 KB | 
| 最終ジャッジ日時 | 2025-01-09 14:09:22 | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 3 | 
ソースコード
#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';
    }
}
            
            
            
        