結果

問題 No.1464 Number Conversion
ユーザー tentententen
提出日時 2021-04-13 12:29:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 6,248 ms
コンパイル使用メモリ 74,496 KB
実行使用メモリ 52,924 KB
最終ジャッジ日時 2023-09-12 00:08:39
合計ジャッジ時間 7,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
52,520 KB
testcase_01 AC 72 ms
50,592 KB
testcase_02 AC 74 ms
50,832 KB
testcase_03 AC 73 ms
52,756 KB
testcase_04 AC 80 ms
52,764 KB
testcase_05 AC 70 ms
51,720 KB
testcase_06 AC 77 ms
52,712 KB
testcase_07 AC 71 ms
51,472 KB
testcase_08 AC 74 ms
52,376 KB
testcase_09 AC 75 ms
52,556 KB
testcase_10 AC 74 ms
52,388 KB
testcase_11 AC 73 ms
50,988 KB
testcase_12 AC 75 ms
51,028 KB
testcase_13 AC 72 ms
51,768 KB
testcase_14 AC 72 ms
52,412 KB
testcase_15 AC 74 ms
51,324 KB
testcase_16 AC 73 ms
52,276 KB
testcase_17 AC 83 ms
52,420 KB
testcase_18 AC 73 ms
52,480 KB
testcase_19 AC 76 ms
52,596 KB
testcase_20 AC 77 ms
52,628 KB
testcase_21 AC 77 ms
52,536 KB
testcase_22 AC 69 ms
51,024 KB
testcase_23 AC 75 ms
52,372 KB
testcase_24 AC 84 ms
52,908 KB
testcase_25 AC 80 ms
52,528 KB
testcase_26 AC 84 ms
52,500 KB
testcase_27 AC 77 ms
52,924 KB
testcase_28 AC 80 ms
52,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        String s = sc.next();
        long x;
        long y = 1;
        if (s.contains(".")) {
            x = Long.parseLong(s.substring(0, s.indexOf(".")));
            int length = s.length() - s.indexOf(".") - 1;
            for (int i = 0; i < length; i++) {
                x *= 10;
                y *= 10;
            }
            x += Long.parseLong(s.substring(s.indexOf(".") + 1, s.length()));
        } else {
            x = Long.parseLong(s);
        }
        long gcd = getGCD(x, y);
        System.out.println((x / gcd) + "/" + (y / gcd));
    }
    
    static long getGCD(long x, long y) {
        if (x % y == 0) {
            return y;
        } else {
            return getGCD(y, x % y);
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0