vector<string> split(const string& input, string delimiter) {
vector<string> result;
auto start = 0;
auto end = input.find(delimiter);
while (end != string::npos) {
result.push_back(input.substr(start, end - start)); //start~idx 까지 문자열 넣기
start = end + delimiter.size(); //start 변경
end = input.find(delimiter, start); //start부터 delimiter 찾기
}
result.push_back(input.substr(start)); //마지막 문자열 넣기
return result;
}
→ 오름차순으로 배열의 순열을 만음
→ 내림차순 배열의 순열
⇒ 배열을 정렬한 뒤에 사용!
vector<int> v = {1,2,3};
do{
//1, 2, 3부터 오름차순으로 순열을 뽑음
for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
}while(next_permutation(v.begin(), v.end()));
//while(next_permutation(v.begin(), v.begin()+2); -> 처음부터 2개만 순열을 만듬
//while(next_permutation(a, a+3); -> array로도 사용 가능
int n = 5, k = 3;
int a[5] = {1, 2, 3, 4, 5};
void combi(int start, vector<int> &b)
{
if (b.size() == k)
{
//nCk 로 뽑은 배열로 수행할 로직
return;
}
for (int i = start + 1; i < n; i++)
{
b.push_back(i);
combi(i, b);
b.pop_back();
}
return;
}
int main()
{
vector<int> b;
combi(-1, b); // -1부터 시작
return 0;
}