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>
- vector<string> GetPermutations(It range_begin, It range_end) {
- vector<string> result;
- string s="";
- for(auto it = range_begin; it!=range_end; ++it)
- {
- s+=to_string(*it);
- }
- sort(s.begin(), s.end(), greater<char>());
- do {
- string ss="";
- string prob="";
- for (char c : s){
- ss=ss+prob+c;
- prob=" ";
- }
- result.push_back(ss);
- } while (prev_permutation(s.begin(), s.end()));
- return result;
- }
- // функция, записывающая элементы диапазона в строку
- template <typename It>
- string PrintRangeToString(It range_begin, It range_end) {
- ostringstream out;
- for (auto it = range_begin; it != range_end; ++it) {
- out << *it << " "s;
- }
- out << endl;
- // получаем доступ к строке с помощью метода str для ostringstream
- return out.str();
- }
- 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 << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement