๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœจ Algorithm

[๋ฐฑ์ค€/C++] 3009 : ๋„ค ๋ฒˆ์งธ ์ 

by nitronium102 2021. 8. 12.

๋ฌธ์ œ

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

์ž…๋ ฅ

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

์ถœ๋ ฅ

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

ํ’€์ด

if๋ฌธ์„ ์ด์šฉํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค! 

#include <iostream>
using namespace std;

int main(){
  int x[3], y[3];
  for (int i=0; i<3; i++){
    cin >> x[i] >> y[i];  
  }
  
  int x4, y4;
  
  if (x[0] == x[1])
    x4 = x[2];
  else if (x[0] == x[2])
    x4 = x[1];
  else
    x4 = x[0];

  if (y[0] == y[1])
    y4 = y[2];
  else if (y[0] == y[2])
    y4 = y[1];
  else
    y4 = y[0];

  cout << x4 << " " << y4;
}

๋Œ“๊ธ€