結果

問題 No.539 インクリメント
ユーザー nebukuro09nebukuro09
提出日時 2019-04-18 11:11:56
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 101,844 KB
実行使用メモリ 7,012 KB
最終ジャッジ日時 2023-09-04 00:38:01
合計ジャッジ時間 1,730 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

bool is_num(dchar x) {
    return '0' <= x && x <= '9';
}

bool is_ten(dchar x) {
    return x - '0' == 10;
}

void solve() {
    auto S = ('a' ~ readln.chomp).to!(dchar[]);

    int status = 0;
    int carry = 0;

    dchar increment(dchar x) {
        if ((x + 1).is_ten) {
            carry = 1;
            return '0';
        } else {
            carry = 0;
            return x + 1;
        }
    }

    foreach_reverse (i; 0..S.length.to!int) {
        if (status == 0 && S[i].is_num) {
            status = 1;
            S[i] = increment(S[i]);
        } else if (status == 1 && S[i].is_num) {
            if (carry) {
                S[i] = increment(S[i]);
            }
        } else if (status == 1 && !S[i].is_num) {
            if (carry) {
                S = S[0..i+1] ~ '1' ~ S[i+1..$];
            }
            break;
        }
    }

    S[1..$].writeln;
}

void main(){
    auto T = readln.chomp.to!int;
    while (T--) solve;
}
0