Advertisement
a53

Cuvinte12

a53
Dec 21st, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. #define N 11
  6. int x[N],n,m;
  7. char s[N],vocala[]="aeiou";
  8.  
  9. void afis(int k)
  10. {
  11. for(int i=1;i<=k;++i)
  12. cout<<s[x[i]-1];
  13. cout<<'\n';
  14. }
  15.  
  16. bool valid(int k)
  17. {
  18. if(k==1)
  19. {
  20. if(strchr(vocala,s[x[k]-1])==NULL)
  21. return false;
  22. else
  23. return true;
  24. }
  25. else
  26. {
  27. if(x[k]<=x[k-1])
  28. return false;
  29. else
  30. if(strchr(vocala,s[x[k]-1])==NULL&&strchr(vocala,s[x[k-1]-1])==NULL)
  31. return false;
  32. else
  33. return true;
  34. }
  35. return true;
  36. }
  37.  
  38. void backtracking(int k)
  39. {
  40. for(int i=1;i<=n;++i)
  41. {
  42. x[k]=i;
  43. if(k<=m&&valid(k))
  44. afis(k),backtracking(k+1);
  45. }
  46. }
  47.  
  48. int main()
  49. {
  50. cin>>s;
  51. n=strlen(s);
  52. sort(s,s+n);
  53. cin>>m;
  54. backtracking(1);
  55. return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement