Algorithm

[๋ฐฑ์ค€ 2309] ์ผ๊ณฑ ๋‚œ์Ÿ์ด

osean 2023. 3. 28. 21:04

๋ฌธ์ œ

 

2309๋ฒˆ: ์ผ๊ณฑ ๋‚œ์Ÿ์ด

์•„ํ™‰ ๊ฐœ์˜ ์ค„์— ๊ฑธ์ณ ๋‚œ์Ÿ์ด๋“ค์˜ ํ‚ค๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ํ‚ค๋Š” 100์„ ๋„˜์ง€ ์•Š๋Š” ์ž์—ฐ์ˆ˜์ด๋ฉฐ, ์•„ํ™‰ ๋‚œ์Ÿ์ด์˜ ํ‚ค๋Š” ๋ชจ๋‘ ๋‹ค๋ฅด๋ฉฐ, ๊ฐ€๋Šฅํ•œ ์ •๋‹ต์ด ์—ฌ๋Ÿฌ ๊ฐ€์ง€์ธ ๊ฒฝ์šฐ์—๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ์ถœ๋ ฅํ•œ๋‹ค.

www.acmicpc.net

ํ’€์ด

#include <bits/stdc++.h>
using namespace std;

int main() {
  // ์ž…๋ ฅ๋œ ๋‚œ์Ÿ์ด๋“ค์˜ ํ‚ค
  int array[9];

  for (int i = 0; i < 9; i++) {
    cin >> array[i];
  }

  // ๋‚œ์Ÿ์ด ์ •๋ ฌ (์˜ค๋ฆ„์ฐจ์ˆœ)
  for (int n = 0; n < 9; n++) {
    for (int m = n + 1; m < 9; m++) {
      if (array[m] <= array[n]) {
        int tmp = array[n];
        array[n] = array[m];
        array[m] = tmp;
      }
    }
  }

  // ๋‚œ์Ÿ์ด๋“ค์˜ ํ‚ค ํ•ฉ
  int totalLength = 0;
  for (int i: array) {
    totalLength += i;
  }

  // ์ œ์™ธํ•  ๋‚œ์Ÿ์ด๋“ค
  int exclude[2];

  // ์ฐพ๊ธฐ
  for (int n = 0; n < 9; n++) {
    for (int m = n + 1; m < 9; m++) {
      int result = totalLength - array[n] - array[m];
      if (result == 100) {
        exclude[0] = n;
        exclude[1] = m;
        break;
      }
    }
  }

  cout << "\n";
  // ์ธ๋ฑ์Šค
  int index = 0;
  // ๊ฒฐ๊ณผ
  int result[7];

  for (int i = 0; i < 9; i++) {
    if (i != exclude[0] && i != exclude[1]) {
      result[index] = array[i];
      index++;
    }
  }

  for (int i: result) {
    cout << i << "\n";
  }
    
  return 0;
}