結果

問題 No.539 インクリメント
ユーザー PachicobuePachicobue
提出日時 2017-06-30 23:47:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,507 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 168,832 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 07:12:53
合計ジャッジ時間 2,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define show(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz=" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = 1e9 + 7;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

inline int isnum(const char c)
{
    if (c >= '0' and c <= '9') {
        return c - '0';
    } else {
        return -1;
    }
}

int main()
{
    int T;
    cin >> T;
    string dummy;
    getline(std::cin, dummy);
    for (auto t = 0; t < T; t++) {
        string s;
        getline(std::cin, s);
        int i = s.size() - 1;
        bool flag = true;
        int tail = 0;
        int pos = 0;
        ll numnum = 0;
        bool trail = false;
        bool contain = false;
        int size = 0;
        for (; i >= 0 and flag;) {
            if (isnum(s[i]) == -1) {
                i--;
                continue;
            } else {
                contain = true;
                tail = max(tail, i);
                string stnum;
                while (i >= 0) {
                    if (isnum(s[i]) != -1) {
                        stnum.push_back(s[i]);
                    } else {
                        pos = i;
                        flag = false;
                        break;
                    }
                    i--;
                }
                reverse(stnum.begin(), stnum.end());
                if (stnum[0] == '0') {
                    trail = true;
                    size = stnum.size();
                }
                numnum = stoll(stnum);
            }
        }
        if (not contain) {
            cout << s << endl;
            continue;
        }
        numnum++;
        string newst = to_string(numnum);
        const int prev_size = newst.size();
        if (trail) {
            for (int i = 0; i < size - prev_size - 1; i++) {
                newst = "0" + newst;
            }
        }
        for (int i = 0; i <= pos; i++) {
            cout << s[i];
        }
        cout << newst;
        for (int i = tail + 1; i < s.size(); i++) {
            cout << s[i];
        }
        cout << endl;
    }
    return 0;
}
0