bool find_operator_combination(const int* numbers, char* operators, int count, int answer)

{

    if (count < 1) return answer == 0;

    *operators = '+';

    if (find_operator_combinations(numbers + 1, operators + 1, count - 1, answer - *numbers)) return true;

    *operators = '-';

    if (find_operator_combinations(numbers + 1, operators + 1, count - 1, answer + *numbers)) return true;

    return false;

}


가령,

int a[4] = {1, 3, 5, 7};

char o[4] = {0, };


처럼해서,

find_operator_combination(a, o, 4, 6);


호출하면, ? 1 ? 3 ? 5 ? 7 = 6 인 조합을 o 배열에 채워줌.

첫 기호는 첫 숫자의 부호가 되는 셈이니까 유의.

1 + 3 - 5 + 7 = 6 을 출력하고 싶으면 부호를 두번째부터(o[1]) 출력해야함.