Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <numeric>
- #include <sstream>
- #include <vector>
- using namespace std;
- // функция, записывающая элементы диапазона в строку
- template <typename It>
- string PrintRangeToString(It range_begin, It range_end) {
- ostringstream out;
- for (auto it = range_begin; it != range_end; ++it) {
- out << *it << " ";
- }
- out << endl;
- return out.str();
- }
- template <typename It>
- vector<string> GetPermutations(It range_begin, It range_end){
- vector<string> result;
- sort(range_begin, range_end);
- do{
- result.push_back(PrintRangeToString(range_begin, range_end));
- }while(next_permutation(range_begin, range_end));
- return result;
- }
- int main() {
- vector<int> permutation(3);
- iota(permutation.begin(), permutation.end(), 1);
- auto result = GetPermutations(permutation.begin(), permutation.end());
- for (const auto& s : result) {
- cout << s;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement