본문 바로가기

카테고리 없음

[C++]조합 만들기

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int comb(string order, int pos, int wish,int count,string push_order,  vector <string> &table)
{
	if (pos > order.length())
	{
		return 1;
	}
	if (count == wish)
	{
		cout << push_order << endl;
		table.push_back(push_order);
		return 1;
	}
	comb(order, pos + 1, wish, count, push_order, table);
	push_order.append(1, order[pos]);
	comb(order, pos + 1, wish, count + 1, push_order, table);
}
int main (void)
{
	vector <string> table;
	string order = "ABCDE";
	string push_order = "";
	comb(order, 0, 3, 0, push_order, table);
	comb(order, 0, 1,0, push_order, table);
	comb(order, 0, 2, 0, push_order, table);

	cout << order.append("def") << endl;

}