Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<algorithm>
- #include<set>
- #define long long long
- #define nln '\n'
- const long N = 20;
- using namespace std;
- // GLobal variables: cow, m, n, a
- fstream f1,f2;
- inline void openf()
- {
- f1.open("qbhv.inp", ios:: in);
- f2.open("qbhv.out", ios:: out);
- }
- inline void closef()
- {
- f1.close();
- f2.close();
- }
- string str;
- long n;
- vector<short> a;
- void data()
- {
- f1.tie(0)->sync_with_stdio(0);
- f2.tie(0)->sync_with_stdio(0);
- //cin.tie(0)->sync_with_stdio(0);
- cin >> str;
- n = str.size();
- for (long i = 0; i != n; ++i)
- a.push_back(i);
- }
- set<string> sav;
- void show()
- {
- string tem = "";
- for (const auto &i : a)
- tem += str[i];
- sav.insert(tem);
- }
- void swap(long &a, long &b)
- {
- long itm = a;
- a = b;
- b = itm;
- }
- bool stop = 0;
- void gen()
- {
- long i = n-2;
- while (a[i] > a[i+1] && i != -1)
- --i;
- if (i == -1)
- {
- stop = 1;
- return;
- }
- long j = n-1;
- while (a[j] < a[i])
- --j;
- swap(a[i], a[j]);
- long lef = i+1, rig = n-1;
- while (lef < rig)
- {
- swap(a[lef], a[rig]);
- ++lef; --rig;
- }
- }
- void process()
- {
- while (!stop)
- {
- show();
- gen();
- }
- }
- void view()
- {
- cout << sav.size() << nln;
- for (const auto &i : sav)
- cout << i << nln;
- }
- int main()
- {
- openf();
- data();
- process();
- view();
- closef();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment