a53

Cuvinte11

a53
Nov 21st, 2021 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. int n,m,x[12];
  6. char s[12],v[]="aeiou";
  7.  
  8. void afis(int k)
  9. {
  10. if(k>=m&&strchr(v,s[x[k]-1])==NULL) /// si ultima e consoana
  11. {
  12. for(int i=1;i<=k;++i)
  13. cout<<s[x[i]-1];
  14. cout<<'\n';
  15. }
  16. }
  17.  
  18. bool valid(int k)
  19. {
  20. if(k==1) /// Daca am doar o litera, atunci sunt indeplinite conditiile.
  21. return true;
  22. if(x[k]>x[k-1])
  23. {
  24. if(strchr(v,s[x[k]-1])!=NULL&&strchr(v,s[x[k-1]-1])!=NULL)
  25. return false; ///doua vocale alaturate => fals
  26. else
  27. return true;
  28. }
  29. return false;
  30. }
  31.  
  32. void Back(int k)
  33. {
  34. for(int i=x[k-1]+1;i<=n;++i)
  35. {
  36. x[k]=i;
  37. if(valid(k))
  38. {
  39. afis(k);
  40. Back(k+1);
  41. }
  42. }
  43. }
  44.  
  45. int main()
  46. {
  47. cin>>s>>m;
  48. n=strlen(s);
  49. sort(s,s+n);
  50. Back(1);
  51. return 0;
  52. }
  53.  
Add Comment
Please, Sign In to add comment