백준 - 3040 : 백설 공주와 일곱 난쟁이 [자바]

HungAh.log·2021년 8월 12일
0
post-custom-banner
import java.io.*;
import java.util.*;

public class Main {
	static int[] numbers;
	static StringBuilder sb = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int[] nan = new int[9];
		numbers = new int[7];
		for (int i = 0; i < 9; i++) {
			nan[i] = Integer.parseInt(br.readLine());
		}
		combination(0, 0, nan);
		System.out.println(sb.toString());

	}

	//조합
	static void combination(int cnt, int start, int[] nan) {
		if (cnt == 7) {
			int sum = 0;
			for (int i = 0; i < numbers.length; i++) {
				sum += numbers[i];
			}
			if (sum == 100) {
				for (int i = 0; i < numbers.length; i++) {
					sb.append(numbers[i]).append("\n");
				}
				return;
			}
			return;
		}

		for (int i = start; i < nan.length; i++) {
			numbers[cnt] = nan[i];
			combination(cnt + 1, i + 1, nan);

		}
	}
}
profile
👩🏻‍💻
post-custom-banner

0개의 댓글