inblog logo
|
LHS's Study Space
    알고리즘문제풀기랜덤마라톤

    [랜덤 마라톤] 단원평가(31798)

    lhs's avatar
    lhs
    Jan 01, 2025
    [랜덤 마라톤] 단원평가(31798)
    Contents
    1. 문제 풀이 아이디어2. 나의 정답 코드3. 정리
    www.acmicpc.net
    https://www.acmicpc.net/problem/31798
    notion image
    notion image

    1. 문제 풀이 아이디어

    • 3가지 경우로 나누어 계산하여 문제를 해결할 수 있다.

    2. 나의 정답 코드

    public class Main { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine()); int a = Integer.parseInt(stringTokenizer.nextToken()); int b = Integer.parseInt(stringTokenizer.nextToken()); int c = Integer.parseInt(stringTokenizer.nextToken()); if (a == 0) { System.out.println(c * c - b); } else if (b == 0) { System.out.println(c * c - a); } else { System.out.println((int) Math.sqrt(a + b)); } bufferedReader.close(); } }

    3. 정리

    • a나 b가 0일 경우, c의 제곱에서 b나 a를 뺀 값을 출력한다.
    • c가 0일 경우, a + b의 제곱근을 계산한 후 정수로 변환하여 출력한다.
    Share article
    Contents
    1. 문제 풀이 아이디어2. 나의 정답 코드3. 정리

    LHS's Study Space

    RSS·Powered by Inblog