Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- bool cons(char c) {
- return (c!='a' and c!='o');
- }
- int main() {
- string s="coca-cola";
- sort(s.begin(),s.end());
- int n=s.size();
- int ans=0;
- do{
- bool ok=true;
- if (s[0]=='-' or s[n-1]=='-') ok=false;
- //no hi ha dos consonants
- for (int i=1;ok and i<n;++i)
- if (cons(s[i]) and cons(s[i-1])) ok=false;
- if (ok) {
- printf("%s\n",s.c_str());
- ++ans;
- }
- }while(next_permutation(s.begin(),s.end()));
- cout << endl;
- cout << ans << " RESULTATS"<<endl;
- }
Add Comment
Please, Sign In to add comment