본문 바로가기

Algorithm/CodeUp

[CodeUp_Java] Q1732 : 나눗셈과 제곱

반응형

안녕하세요! Plitche(플리체)입니다.
이번 포스팅의 주제는 Q1732 나눗셈과 제곱 (자바, JAVA)입니다.

Intro

Question

문제 설명

입력

정수 a, b 두 개가 공백으로 분리되어 입력된다.

출력

첫째 줄에 a÷b의 계산 결과(몫)를 소숫점 둘째 자리에서 반올림하여 첫째 자리까지 출력한다.
둘째 줄에 a÷b의 계산 결과(몫)를 소수점 이하를 버린 결과를 출력한다.
셋째 줄에 ab의 결과를 출력한다.

예시

  • 입력 : 4 3
  • 출력 :
    1.3
    1
    64

Solution (풀이)

  • 풀이 : 메모리 14256, 시간 : 111
public class Answer1 {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");

        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());

        sb.append(String.format("%.1f", a/1.0/b)).append("\n").append(a/b).append("\n").append((int)Math.pow(a, b));

        System.out.println(sb);
    }

}

Ranking(순위)

반응형