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

[BOJ/Step9] 3009 : ๋„ค ๋ฒˆ์งธ ์  (JAVA)

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

www.acmicpc.net/problem/3009

 

3009๋ฒˆ: ๋„ค ๋ฒˆ์งธ ์ 

์„ธ ์ ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ถ•์— ํ‰ํ–‰ํ•œ ์ง์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ ํ•„์š”ํ•œ ๋„ค ๋ฒˆ์งธ ์ ์„ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net


๋ฌธ์ œ

์„ธ ์ ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ถ•์— ํ‰ํ–‰ํ•œ ์ง์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ ํ•„์š”ํ•œ ๋„ค ๋ฒˆ์งธ ์ ์„ ์ฐพ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์„ธ ์ ์˜ ์ขŒํ‘œ๊ฐ€ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ขŒํ‘œ๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 1000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜์ด๋‹ค.

 

์ถœ๋ ฅ

์ง์‚ฌ๊ฐํ˜•์˜ ๋„ค ๋ฒˆ์งธ ์ ์˜ ์ขŒํ‘œ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 

30 20

10 10

10 20

 

์˜ˆ์ œ ์ถœ๋ ฅ 

30 10


ํ’€์ด

1. ์„ธ ์ ์ด ์ฃผ์–ด์กŒ๋Š”๋ฐ ํ•œ ์ ์„ ์ฐ์Œ์œผ๋กœ์„œ ํ•ญ์ƒ ์ง์‚ฌ๊ฐํ˜•์ด ๋งŒ๋“ค์–ด์ง„๋‹ค๋Š” ๊ฑด, ์ฃผ์–ด์ง€๋Š” ์„ธ ์ ์ด ๋ฌด์กฐ๊ฑด ์ง๊ฐ์œผ๋กœ ์ฃผ์–ด์ง„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. 

2. ์ฃผ์–ด์ง„ ์„ธ ์ ์€ x๋ผ๋ฆฌ, y๋ผ๋ฆฌ ๋ฌถ์—ˆ์„ ๋•Œ ๋‘ ๊ฐœ๋Š” ๊ฐ™๊ณ  ํ•œ ๊ฐœ๋Š” ๋‹ค๋ฅผ ๊ฒƒ์ด๋‹ค. ๋‹ค๋ฅธ ํ•œ ๊ฐœ๋ฅผ ๋ชจ์•„ ๋„ค๋ฒˆ์งธ ์ ์„ ๋งŒ๋“ค์–ด ์ฃผ๋ฉด ๋œ๋‹ค.

 

import java.util.Scanner;

public class B3009 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int x3 = sc.nextInt();
		int y3 = sc.nextInt();
		int x4;
		int y4;
		
		if(x1 == x2) {
			x4 = x3;
		} else if (x2 == x3) {
			x4 = x1;
		} else {
			x4 = x2;
		}
		
		if(y1 == y2) {
			y4 = y3;
		} else if (y2 == y3) {
			y4 = y1;
		} else {
			y4 = y2;
		}

		System.out.println(x4 + " " + y4);
	}
}