Advertisement
J00ker

Untitled

Oct 9th, 2015
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int st[100], n;
  9. char S[9];
  10.  
  11. int Valid(int k)
  12. {
  13.     for(int i = 3; i <= k; i++)
  14.     {
  15.         //cout << S[st[i-2]-1] << " " << S[st[i-1]-1] << " " << S[st[i]-1] << "\n";
  16.         if((strchr("aeiouAEIOU", S[st[i-2]-1]) == 0) &&
  17.            (strchr("aeiouAEIOU", S[st[i-1]-1]) == 0) &&
  18.            (strchr("aeiouAEIOU", S[st[i]-1]) == 0))
  19.             return 0;
  20.     }
  21.     for(int i = 1; i <  k; i++)
  22.         if(st[k] == st[i])
  23.             return 0;
  24.     return 1;
  25. }
  26.  
  27. ofstream fout("anagrame1.out");
  28. void backtrack(int k)
  29. {
  30.     if(k == n+1)
  31.     {
  32.         for(int i = 1; i <= n; i++)
  33.             fout << S[st[i]-1];
  34.         fout << "\n";
  35.     }
  36.     else
  37.     {
  38.         st[k] = 0;
  39.         while(st[k]++ < n)
  40.             if(Valid(k))
  41.                 backtrack(k+1);
  42.     }
  43. }
  44.  
  45. int main()
  46. {
  47.     ifstream fin("anagrame1.in");
  48.     fin.getline(S, 9);
  49.     n = strlen(S);
  50.     //sort(S, S+n);
  51.     backtrack(1);
  52.     fin.close();
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement