Advertisement
WadeRollins2710

UET Password Generator

Mar 14th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. //Trần Việt Anh - 14/3/2019 - 5:40PM
  2. #include<iostream>
  3. #include<vector>
  4.  
  5. using namespace std;
  6.  
  7. vector<string> result(0, "");
  8.  
  9. void go(string current, string charset)
  10. {
  11.     if (current.length() < charset.length())
  12.         for (int i = 0; i < charset.length(); i++)
  13.         {
  14.             result.push_back(current + charset[i]);
  15.             go(current + charset[i], charset);
  16.         }
  17. }
  18.  
  19. int main()
  20. {
  21.     string _set; cin >> _set;
  22.     string s = "";
  23.  
  24.     //Generate the result
  25.     go(s, _set);
  26.  
  27.     //Reorder the result to match the output rule
  28.     for (int i = 0; i < result.size() - 1; i++)
  29.         for (int j = i + 1; j < result.size(); j++)
  30.             if (result[i].length() > result[j].length())
  31.             {
  32.                 string mid = result[i]; result[i] = result[j]; result[j] = mid;
  33.             }
  34.             else if (result[i].length() == result[j].length() && result[i] > result[j])
  35.             {
  36.                 string mid = result[i]; result[i] = result[j]; result[j] = mid;
  37.             }
  38.  
  39.     //Print the result
  40.     for (int i = 0; i < result.size(); i++)
  41.         cout << result[i] << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement