結果

問題 No.1464 Number Conversion
ユーザー tentententen
提出日時 2023-08-04 09:06:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 2,162 bytes
コンパイル時間 3,609 ms
コンパイル使用メモリ 96,108 KB
実行使用メモリ 40,128 KB
最終ジャッジ日時 2024-04-22 06:54:05
合計ジャッジ時間 7,525 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
38,380 KB
testcase_01 AC 84 ms
39,908 KB
testcase_02 AC 84 ms
39,764 KB
testcase_03 AC 83 ms
38,732 KB
testcase_04 AC 86 ms
38,320 KB
testcase_05 AC 94 ms
38,332 KB
testcase_06 AC 99 ms
38,092 KB
testcase_07 AC 99 ms
40,128 KB
testcase_08 AC 82 ms
38,468 KB
testcase_09 AC 84 ms
38,348 KB
testcase_10 AC 97 ms
39,888 KB
testcase_11 AC 85 ms
40,012 KB
testcase_12 AC 93 ms
38,220 KB
testcase_13 AC 83 ms
39,820 KB
testcase_14 AC 87 ms
39,636 KB
testcase_15 AC 85 ms
38,600 KB
testcase_16 AC 85 ms
40,124 KB
testcase_17 AC 93 ms
39,632 KB
testcase_18 AC 99 ms
40,000 KB
testcase_19 AC 99 ms
39,764 KB
testcase_20 AC 84 ms
38,356 KB
testcase_21 AC 93 ms
38,980 KB
testcase_22 AC 84 ms
39,764 KB
testcase_23 AC 83 ms
40,000 KB
testcase_24 AC 83 ms
40,096 KB
testcase_25 AC 90 ms
39,628 KB
testcase_26 AC 87 ms
40,084 KB
testcase_27 AC 85 ms
38,368 KB
testcase_28 AC 81 ms
38,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        StringBuilder sb = new StringBuilder();
        boolean hasPoint = false;
        long base = 1;
        for (char c : inputs) {
            if (c == '.') {
                hasPoint = true;
            } else {
                sb.append(c);
                if (hasPoint) {
                    base *= 10;
                }
            }
        }
        long value = Long.parseLong(sb.toString());
        long gcd = getGCD(value, base);
        value /= gcd;
        base /= gcd;
        System.out.println(value + "/" + base);
    }
    
    static long getGCD(long x, long y) {
        if (y == 0) {
            return x;
        } else {
            return getGCD(y, x % y);
        }
    }
} 
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0