結果
| 問題 | No.539 インクリメント |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-18 11:11:56 |
| 言語 | D (dmd 2.111.0) |
| 結果 |
AC
|
| 実行時間 | 57 ms / 2,000 ms |
| コード長 | 1,149 bytes |
| 記録 | |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 116,708 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-22 00:44:38 |
| 合計ジャッジ時間 | 1,709 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 |
ソースコード
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;
}