Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- #define N 11
- int x[N],n,m;
- char s[N],vocala[]="aeiou";
- void afis(int k)
- {
- for(int i=1;i<=k;++i)
- cout<<s[x[i]-1];
- cout<<'\n';
- }
- bool valid(int k)
- {
- if(k==1)
- {
- if(strchr(vocala,s[x[k]-1])==NULL)
- return false;
- else
- return true;
- }
- else
- {
- if(x[k]<=x[k-1])
- return false;
- else
- if(strchr(vocala,s[x[k]-1])==NULL&&strchr(vocala,s[x[k-1]-1])==NULL)
- return false;
- else
- return true;
- }
- return true;
- }
- void backtracking(int k)
- {
- for(int i=1;i<=n;++i)
- {
- x[k]=i;
- if(k<=m&&valid(k))
- afis(k),backtracking(k+1);
- }
- }
- int main()
- {
- cin>>s;
- n=strlen(s);
- sort(s,s+n);
- cin>>m;
- backtracking(1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement