[백준] C++ 2309번 일곱난쟁이

yewonjune·2026년 2월 5일

백준을 풀어보자

목록 보기
11/12

백준 2309번 일곱난쟁이
https://www.acmicpc.net/problem/2309

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

int a[9];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

	sort(a, a + 9);

	do {
		int sum = 0;

		for (int i = 0; i < 7; i++)
		{
			sum += a[i];
		}

		if (sum == 100) break;
	} while (next_permutation(a, a + 9));

	for (int i = 0; i < 7; i++) cout << a[i] << "\n";

	return 0;
}

  • next_permutation(v.begin(), v.end()) : n개의 원소의 순열을 구할 때 사용하는 함수
profile
게임만드는 백수

0개의 댓글