Advertisement
coregame

C++ Lab13 String Permutation

Apr 26th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <sstream>
  5. #include <algorithm>
  6. #include <iterator>
  7.  
  8. using namespace std;
  9.  
  10. void printVector(std::vector<string> vec) {
  11.     copy(vec.begin(), vec.end(), ostream_iterator<string>(cout, " "));
  12.     cout << endl;
  13. }
  14.  
  15. int main() {
  16.     string userinput;
  17.     int counter = 0;
  18.  
  19.     cout << "Enter text: ";
  20.     getline(cin, userinput);
  21.  
  22.     stringstream ss(userinput);
  23.     istream_iterator<string> begin(ss);
  24.     istream_iterator<string> end;
  25.     vector<string> vstrings(begin, end);
  26.     cout << endl;
  27.  
  28.     sort(vstrings.begin(), vstrings.end());
  29.  
  30.     do {
  31.         printVector(vstrings);
  32.         counter++;
  33.     } while (next_permutation(vstrings.begin(), vstrings.end()));
  34.  
  35.     cout << endl << counter << " Possible output." << endl;
  36.     system("pause");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement