結果

問題 No.1464 Number Conversion
コンテスト
ユーザー kokatsu
提出日時 2021-11-09 19:48:14
言語 D
(dmd 2.112.0)
コンパイル:
dmd -fPIE -m64 -w -wi -O -release -inline -I/opt/dmd/src/druntime/import/ -I/opt/dmd/src/phobos -L-L/opt/dmd/linux/lib64/ -fPIC _filename_
実行:
./Main
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 460 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 794 ms
コンパイル使用メモリ 173,584 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-06 18:43:40
合計ジャッジ時間 1,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/linuxbrew/.linuxbrew/opt/dmd/include/dlang/dmd/std/numeric.d(3011): Warning: cannot inline function `std.numeric.gcdImpl!ulong.gcdImpl`
private typeof(T.init % T.init) gcdImpl(T)(T a, T b)
                                ^

ソースコード

diff #
raw source code

import std;

void main() {
    string X = readln.chomp;

    bool afterDecimalPoint;
    long num, den = 1;
    foreach (x; X) {
        if (x == '.') {
            afterDecimalPoint = true;
        }
        else {
            num = num * 10 + (x - '0');
            if (afterDecimalPoint) {
                den *= 10;
            }
        }
    }

    long g = gcd(num, den);
    if (g > 0) {
        num /= g, den /= g;
    }

    writeln(num, "/", den);
}
0