Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int n,m,x[12];
- char s[12],v[]="aeiou";
- void afis(int k)
- {
- if(k>=m&&strchr(v,s[x[k]-1])==NULL) /// si ultima e consoana
- {
- for(int i=1;i<=k;++i)
- cout<<s[x[i]-1];
- cout<<'\n';
- }
- }
- bool valid(int k)
- {
- if(k==1) /// Daca am doar o litera, atunci sunt indeplinite conditiile.
- return true;
- if(x[k]>x[k-1])
- {
- if(strchr(v,s[x[k]-1])!=NULL&&strchr(v,s[x[k-1]-1])!=NULL)
- return false; ///doua vocale alaturate => fals
- else
- return true;
- }
- return false;
- }
- void Back(int k)
- {
- for(int i=x[k-1]+1;i<=n;++i)
- {
- x[k]=i;
- if(valid(k))
- {
- afis(k);
- Back(k+1);
- }
- }
- }
- int main()
- {
- cin>>s>>m;
- n=strlen(s);
- sort(s,s+n);
- Back(1);
- return 0;
- }
Add Comment
Please, Sign In to add comment