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

lhs's avatar
Jan 01, 2025
[랜덤 마라톤] 단원평가(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. 정리

  • ab가 0일 경우, c의 제곱에서 ba를 뺀 값을 출력한다.
  • c가 0일 경우, a + b의 제곱근을 계산한 후 정수로 변환하여 출력한다.
Share article

LHS's Study Space