2
문자열의 벡터에 대한 모든 순열을 인쇄하려고합니다.문자열의 벡터의 next_permutation이 하나의 순열을 건너 뜁니다.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
vector<string> v;
v.push_back("+1");
v.push_back("x4");
do {
cout << v[0] << " " << v[1] << endl;
} while (next_permutation(v.begin(), v.end()));
}
출력 :
+1 x4
x4 +1
을하지만 "* 4"를 next_pemutation 루프 반복을 위해 한 번만 "X4"를 변경할 때이 코드는 의도 한대로 작동합니다.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
vector<string> v;
v.push_back("+1");
v.push_back("*4");
do {
cout << v[0] << " " << v[1] << endl;
} while (next_permutation(v.begin(), v.end()));
}
출력 : # 같은
+1 *4
다른 문자는 같은 효과를 갖고있는 것 같아요. 왜 그런가?
"+1" < "x4"
('+' < 'x'
) :
그것은 그들 모두를 통해 갈 정렬을 시작해야합니다. – chris
"다음"은 "모든 순열의 특정 순서에서 다음"을 의미합니다. –
실제로 [설명서] (http://en.cppreference.com/w/cpp/algorithm/next_permutation)의 어느 부분을 이해할 수 없는지 먼저 설명해 주시면 유용한 답변을 드릴 수 있습니다. –