Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- const int MAX_SIZE = 100;
- string words[MAX_SIZE];
- int counter = 0;
- void print_permutations(string s)
- {
- bool exists = true;
- int i=0;
- int j=0;
- srand(time(NULL));
- for(int k = 0; k < s.length()/2; ++k)
- {
- i = rand()%s.length();//-1;
- j = rand()%s.length();//-1
- /*if (i < 0)
- i = 0;
- if (j < 0)
- j = 0;
- if (i == j)
- i++;
- if (i > s.length()-1)
- i = 0;*/
- if(i != j){
- s[i] = s[i] ^ s[j];
- s[j] = s[i] ^ s[j];
- s[i] = s[i] ^ s[j];
- }
- }
- if(exists == true)
- {
- for(int m = 0; m < MAX_SIZE; m++)
- {
- if(words[m] == s)
- {
- cout << "Permutation exists" << endl;
- }
- break;
- }
- }else
- {
- words[counter] = s;
- cout << "permutation: " << s << endl;;
- }
- }
- int main()
- {
- string word;
- do{
- cout << "\nPlease enter a word" << endl << "Original Word: ";
- cin >> word;
- print_permutations(word);
- counter++;
- }while(word != "1");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement