์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Java

[BOJ/Step9] 4153 : ์ง๊ฐ์‚ผ๊ฐํ˜• (JAVA)

NaNaRin๐Ÿ™ƒ 2021. 1. 19. 21:27

www.acmicpc.net/problem/4153

 

4153๋ฒˆ: ์ง๊ฐ์‚ผ๊ฐํ˜•

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋กœ ์ฃผ์–ด์ง€๋ฉฐ ๋งˆ์ง€๋ง‰์ค„์—๋Š” 0 0 0์ด ์ž…๋ ฅ๋œ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋Š” ๋ชจ๋‘ 30,000๋ณด๋‹ค ์ž‘์€ ์–‘์˜ ์ •์ˆ˜๋กœ ์ฃผ์–ด์ง€๋ฉฐ, ๊ฐ ์ž…๋ ฅ์€ ๋ณ€์˜ ๊ธธ์ด๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

www.acmicpc.net


๋ฌธ์ œ

๊ณผ๊ฑฐ ์ด์ง‘ํŠธ์ธ๋“ค์€ ๊ฐ ๋ณ€๋“ค์˜ ๊ธธ์ด๊ฐ€ 3, 4, 5์ธ ์‚ผ๊ฐํ˜•์ด ์ง๊ฐ ์‚ผ๊ฐํ˜•์ธ๊ฒƒ์„ ์•Œ์•„๋ƒˆ๋‹ค. ์ฃผ์–ด์ง„ ์„ธ๋ณ€์˜ ๊ธธ์ด๋กœ ์‚ผ๊ฐํ˜•์ด ์ง๊ฐ์ธ์ง€ ์•„๋‹Œ์ง€ ๊ตฌ๋ถ„ํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋กœ ์ฃผ์–ด์ง€๋ฉฐ ๋งˆ์ง€๋ง‰์ค„์—๋Š” 0 0 0์ด ์ž…๋ ฅ๋œ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค๋Š” ๋ชจ๋‘ 30,000๋ณด๋‹ค ์ž‘์€ ์–‘์˜ ์ •์ˆ˜๋กœ ์ฃผ์–ด์ง€๋ฉฐ, ๊ฐ ์ž…๋ ฅ์€ ๋ณ€์˜ ๊ธธ์ด๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

 

์ถœ๋ ฅ

๊ฐ ์ž…๋ ฅ์— ๋Œ€ํ•ด ์ง๊ฐ ์‚ผ๊ฐํ˜•์ด ๋งž๋‹ค๋ฉด "right", ์•„๋‹ˆ๋ผ๋ฉด "wrong"์„ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

6 8 10

25 52 60

5 12 13

0 0 0

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

right

wrong

right


ํ’€์ด

์ง๊ฐ์‚ผ๊ฐํ˜•์€ ๊ฐ€์žฅ ๊ธด ๋ณ€์˜ ์ œ๊ณฑ์ด ๋‚˜๋จธ์ง€ ๋‘ ๋ณ€์˜ ์ œ๊ณฑ์˜ ํ•ฉ๊ณผ ๊ฐ™๋‹ค

1. ์ •์ˆ˜ ์„ธ๊ฐœ๋ฅผ ์ž…๋ ฅ๋ฐ›๊ณ  ์…‹ ๋ชจ๋‘ 0์ผ๋•Œ ๋ฌดํ•œ๋ฃจํ”„๋ฅผ ํƒˆ์ถœ

2. ๊ฐ€์žฅ ๊ธด ๋ณ€์ด c์— ์ €์žฅ๋˜๋„๋ก ํ•œ๋‹ค.

3. ๊ฐ€์žฅ ๊ธด ๋ณ€์˜ ์ œ๊ณฑ์ด ๋‚˜๋จธ์ง€ ๋‘ ๋ณ€์˜ ์ œ๊ณฑ์˜ ํ•ฉ๊ณผ ๊ฐ™์œผ๋ฉด right์„, ๋‹ค๋ฅด๋ฉด wrong์„ ์ถœ๋ ฅ์‹œํ‚จ๋‹ค.

=> Math.pow() ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ

 

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

public class B4153 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
		
		int a = -1;
		int b = -1;
		int c = -1;
		
		while(true) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			a = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			c = Integer.parseInt(st.nextToken());
			
			if(a == 0 && b == 0 && c == 0 ) {
				break;
			}
			int temp;
			
			if(a > b && a > c) {
				temp = a;
				a = c;
				c = temp;
			} else if ( b > a && b > c) {
				temp = b;
				b = c;
				c = temp;
			}
			
			if(Math.pow(c, 2) == Math.pow(a, 2) + Math.pow(b, 2)) {
				bw.write("right\n");
			}else {
				bw.write("wrong\n");
			}
		}
		bw.flush();
	}
}