結果

問題 No.1464 Number Conversion
ユーザー threepipes_s
提出日時 2021-04-02 22:01:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 2,655 bytes
コンパイル時間 2,550 ms
コンパイル使用メモリ 80,168 KB
実行使用メモリ 39,784 KB
最終ジャッジ日時 2024-12-23 19:22:42
合計ジャッジ時間 5,704 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static ContestScanner in;static Writer out;static StringBuilder sb=new StringBuilder();
    public static void main(String[] args)
    {try{in=new ContestScanner();out=new Writer();Main solve=new Main();solve.solve();
        in.close();out.flush();out.close();}catch(IOException e){e.printStackTrace();}}
    void solve() throws NumberFormatException, IOException{
        String[] xStr = in.nextToken().split("\\.");
        if (xStr.length == 1) {
            System.out.println(xStr[0] + "/1");
            return;
        }
        long diver = 1;
        for (int i = 0; i < xStr[1].length(); i++) {
            diver *= 10;
        }
        long upper = Long.parseLong(xStr[0] + xStr[1]);
        long g = gcd(diver, upper);
        diver /= g;
        upper /= g;
        System.out.println(upper + "/" + diver);
    }

    static long gcd(long a, long b){
        return b == 0 ? a : gcd(b, a % b);
    }
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}
0