Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Trần Việt Anh - 14/3/2019 - 5:40PM
- #include<iostream>
- #include<vector>
- using namespace std;
- vector<string> result(0, "");
- void go(string current, string charset)
- {
- if (current.length() < charset.length())
- for (int i = 0; i < charset.length(); i++)
- {
- result.push_back(current + charset[i]);
- go(current + charset[i], charset);
- }
- }
- int main()
- {
- string _set; cin >> _set;
- string s = "";
- //Generate the result
- go(s, _set);
- //Reorder the result to match the output rule
- for (int i = 0; i < result.size() - 1; i++)
- for (int j = i + 1; j < result.size(); j++)
- if (result[i].length() > result[j].length())
- {
- string mid = result[i]; result[i] = result[j]; result[j] = mid;
- }
- else if (result[i].length() == result[j].length() && result[i] > result[j])
- {
- string mid = result[i]; result[i] = result[j]; result[j] = mid;
- }
- //Print the result
- for (int i = 0; i < result.size(); i++)
- cout << result[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement