結果

問題 No.1464 Number Conversion
ユーザー bluemeganebluemegane
提出日時 2021-04-17 11:38:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 758 bytes
コンパイル時間 1,391 ms
コンパイル使用メモリ 61,296 KB
実行使用メモリ 23,360 KB
最終ジャッジ日時 2023-09-16 18:59:21
合計ジャッジ時間 4,434 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,684 KB
testcase_01 AC 63 ms
21,256 KB
testcase_02 AC 61 ms
19,416 KB
testcase_03 AC 52 ms
20,688 KB
testcase_04 AC 63 ms
23,004 KB
testcase_05 AC 63 ms
23,144 KB
testcase_06 AC 63 ms
23,004 KB
testcase_07 AC 63 ms
21,312 KB
testcase_08 AC 61 ms
21,252 KB
testcase_09 AC 62 ms
19,164 KB
testcase_10 AC 63 ms
21,140 KB
testcase_11 AC 62 ms
21,300 KB
testcase_12 AC 62 ms
23,352 KB
testcase_13 AC 61 ms
21,260 KB
testcase_14 AC 62 ms
21,256 KB
testcase_15 AC 61 ms
19,344 KB
testcase_16 AC 62 ms
23,292 KB
testcase_17 AC 62 ms
21,452 KB
testcase_18 AC 63 ms
21,376 KB
testcase_19 AC 62 ms
21,260 KB
testcase_20 AC 63 ms
23,332 KB
testcase_21 AC 61 ms
21,316 KB
testcase_22 AC 63 ms
23,360 KB
testcase_23 AC 52 ms
20,680 KB
testcase_24 AC 61 ms
23,360 KB
testcase_25 AC 62 ms
21,244 KB
testcase_26 AC 63 ms
21,276 KB
testcase_27 AC 63 ms
23,084 KB
testcase_28 AC 52 ms
18,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        var p = s.IndexOf('.');
        if (p == -1) Console.WriteLine(s + "/1");
        else getAns(s, p);
    }
    static void getAns(string s, int p)
    {
        var s2 = s.Replace(".", "");
        var t1 = long.Parse(s2);
        var t2 = (long)Pow(10, s.Length - (p + 1));
        var gcd = Gcd(t1, t2);
        t1 /= gcd;
        t2 /= gcd;
        Console.WriteLine("{0}/{1}", t1, t2);
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}
0