알고리즘

C++ 알고리즘 - 백준 2309 일곱 난쟁이

마루설아 2025. 1. 19. 18:57

https://www.acmicpc.net/problem/2309

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

void CPP_INIT() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main(void) {
	CPP_INIT();

	int input;
	int total = 0;
	vector<int> v;

	for (int i = 0; i < 9; i++) {
		cin >> input;
		v.push_back(input);
		total += input;
	}

	sort(v.begin(), v.end());


	for (int i = 0; i < v.size(); i++) {
		for (int j = i + 1; j < v.size(); j++) {
			if (v[i] + v[j] == total - 100) {
				v.erase(v.begin() + i);
				v.erase(v.begin() + (j - 1));

				for (int k = 0; k < v.size(); k++) {
					cout << v[k] << endl;
				}

				return 0;
			}			
		}
	}
}