Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- #define NR 12
- using namespace std;
- int x[NR],L,n,k;
- char s[NR-1],c[NR],v[NR];
- void init(int k)
- {
- x[k]=0;
- }
- bool succesor(int k)
- {
- if(x[k]<n)
- return true;
- else
- return false;
- }
- bool continuare(int k)
- {
- for(int i=1;i<=k-1;++i) /// Valorile sa fie distincte
- if(x[k]==x[i])
- return false;
- return true;
- }
- bool solutie(int k)
- {
- if(k==n+1)
- return true;
- else
- return false;
- }
- void afisare()
- {
- int j=0;
- for(int i=1;i<=L;++i)
- if(c[i])
- cout<<c[i];
- else
- cout<<v[x[++j]-1];
- cout<<'\n';
- }
- void backtracking() /// Generam permutarile multimii {1,2,...,n}
- {
- int k=1;
- init(k);
- while(k)
- if(solutie(k))
- {
- afisare();
- --k;
- }
- else
- if(succesor(k))
- {
- ++x[k];
- if(continuare(k))
- ++k;
- }
- else
- {
- init(k);
- --k;
- }
- }
- int main()
- {
- cin>>s;
- L=strlen(s);
- n=0;
- for(int i=0;i<L;++i)
- if(strchr("aeiou",s[i])==0)
- c[i+1]=s[i];
- else
- v[n++]=s[i];
- sort(v,v+n);
- backtracking();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement