fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. string str,input;
  6. int num;
  7.  
  8. void dfs(int cur){
  9. if(str.length()>=num){
  10. cout<<str<<"\n";
  11. return;
  12. }
  13. for(int i=cur;i<input.length()-(num-str.length())+1;i++){
  14. str+=input[i];
  15. dfs(i+1);
  16. str.pop_back();
  17. }
  18. }
  19.  
  20. int main(){
  21. while(!cin.eof()){
  22. // take num chars
  23. cin>>num;
  24. // your string
  25. cin>>input;
  26. sort(input.begin(),input.end());
  27. dfs(0);
  28. }
  29. }
Success #stdin #stdout 0.01s 16064KB
stdin
3
54321
stdout
123
124
125
134
135
145
234
235
245
345