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
| #include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0),cin.tie(0) using namespace std; int n;
signed main(){ IOS; string s;cin>>s; int len = s.size(),num[30]; memset(num,0,sizeof(num)); for(int i=0;i<len;i++){ num[s[i] - 'a'] += 1; } string str; for(int i = 0;i < 26;i++){ while(num[i]){ str += (char)(i + 'a'); num[i]--; } } vector<string> ans; do{ ans.push_back(str); }while(next_permutation(str.begin(),str.end())); cout<<ans.size()<<"\n"; for(auto i : ans)cout<<i<<"\n"; return 0; }
|