-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path31.cpp
More file actions
41 lines (37 loc) · 874 Bytes
/
31.cpp
File metadata and controls
41 lines (37 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
void nextPermutation(vector<int>& nums) {
if (nums.size() < 2)
return;
int max = nums.back();
for(auto it = nums.end() -2 ; it >= nums.begin(); --it) {
if(max <= *it) {
max = *it;
} else {
sort(it + 1, nums.end());
auto up = upper_bound(it + 1, nums.end(), *it);
int tmp = *up;
*up = *it;
*it = tmp;
return;
}
}
sort(nums.begin(), nums.end());
return;
}
int main(){
vector<int> words;
words.push_back(1);
words.push_back(1);
words.push_back(5);
nextPermutation(words);
for(auto i = words.begin(); i != words.end(); ++i)
cout << *i <<endl;
words.clear();
return 1;
}