Post

[BOJ 1008] A/B

Baekjoon Online Judge 1008(Java 11)
[A/B] 문제 풀이

[BOJ 1008] A/B

-> 문제 바로가기



시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초128 MB89195830329425016334.501%

문제


  • 두 정수 A와 B를 입력받은 다음, A/B를 출력하는 프로그램을 작성하시오.


입력


  • 첫째 줄에 A와 B가 주어진다. (0 < A, B < 10)


출력


  • 첫째 줄에 A/B를 출력한다. 실제 정답과 출력값의 절대오차 또는 상대오차가 10-9 이하이면 정답이다.


예제 1


1
2
// 입력
1 3
1
2
// 출력
0.33333333333333333333333333333333

예제 2


1
2
// 입력
4 5
1
2
// 출력
0.8


출처



비슷한 문제



알고리즘 분류








제출



내 제출


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.*;
import java.util.*;

public class Main {
    public static void solution() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());

        bw.write(String.valueOf(a * b));
        bw.flush();
        bw.close();
        br.close();
    }

    public static void main(String[] args) throws IOException {
        solution();
    }
}


런타임메모리
120 ms14380 KB


다른 풀이


1
2
3
4
5
6
7
8
9
10
11
12
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        sc.close();
        System.out.print(a/b);
    }
}


Reference


  • 다른 풀이 : https://opentutorials.org/module/782/6083
This post is licensed under CC BY 4.0 by the author.