結果

問題 No.955 ax^2+bx+c=0
ユーザー htensai
提出日時 2019-12-18 15:36:35
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,389 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 79,772 KB
実行使用メモリ 40,412 KB
最終ジャッジ日時 2024-07-07 00:49:29
合計ジャッジ時間 13,466 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 59 WA * 63
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 3);
        double a = Integer.parseInt(first[0]);
        double b = Integer.parseInt(first[1]);
        double c = Integer.parseInt(first[2]);
        if (a == 0) {
            if (b == 0) {
                if (c == 0) {
                    System.out.println(-1);
                } else {
                    System.out.println(0);
                }
            } else {
                System.out.println(1);
                System.out.println(java.math.BigDecimal.valueOf(c / b).toPlainString());
            }
        } else {
            double d = b * b - 4 * a * c;
            if (d < 0) {
                System.out.println(0);
            } else if (d == 0) {
                System.out.println(1);
                System.out.println(-b / (2 * a));
            } else {
                System.out.println(2);
                double x = (-b + Math.sqrt(d)) / (2 * a);
                double y = (-b - Math.sqrt(d)) / (2 * a);
                System.out.println(java.math.BigDecimal.valueOf(Math.min(x, y)).toPlainString() + " " + java.math.BigDecimal.valueOf(Math.max(x, y)).toPlainString()); 
            }
        }
    }
}
0