結果

問題 No.539 インクリメント
ユーザー TautConyTautCony
提出日時 2017-11-20 12:45:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,496 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 68,156 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-17 08:18:34
合計ジャッジ時間 4,881 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

class Number
{
public:
    string number;
    Number(){}
    Number(string num)
    {
        number = num;
    }
    Number& operator++()
    {
        size_t length = number.size();
        for (int i = length - 1; i >= 0; --i)
        {
            number[i] = ((number[i] - '0') + 1) % 10 + '0';
            if (number[i] != '0') break;
            else if (i == 0) {
                number = "1" + number;
            }
        }
        return *this;
    }
};

int main()
{
    int T;
    cin >> T;
    string line;
    getline(cin, line);
    while(T--)
    {
        getline(cin, line);
        string head = "";
        string num = "";
        string tail = "";
        bool begin = false;
        bool end = false;
        for(int i = line.length() - 1; i >= 0; --i)
        {
            if (end)
            {
                head = line[i] + head;
                continue;
            }

            if (line[i] >= '0' && line[i] <= '9')
            {
                begin = true;
                num = line[i] + num;
            }
            else
            {
                if (!begin)
                {
                    tail = line[i] + tail;
                    continue;
                }
                end = true;
                head = line[i] + head;
            }
        }
        Number number(num);
        ++number;
        cout << head << number.number  << tail << endl;
    }
}
0