Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5. bool cons(char c) {
  6. return (c!='a' and c!='o');
  7. }
  8.  
  9. int main() {
  10. string s="coca-cola";
  11. sort(s.begin(),s.end());
  12. int n=s.size();
  13. int ans=0;
  14. do{
  15. bool ok=true;
  16. if (s[0]=='-' or s[n-1]=='-') ok=false;
  17. //no hi ha dos consonants
  18. for (int i=1;ok and i<n;++i)
  19. if (cons(s[i]) and cons(s[i-1])) ok=false;
  20.  
  21. if (ok) {
  22. printf("%s\n",s.c_str());
  23. ++ans;
  24. }
  25. }while(next_permutation(s.begin(),s.end()));
  26. cout << endl;
  27. cout << ans << " RESULTATS"<<endl;
  28. }
Add Comment
Please, Sign In to add comment