fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. void File()
  5. {
  6. freopen("in.txt","r",stdin);
  7. freopen("out.txt","w",stdout);
  8. }
  9. string s,ans="";
  10. ll cnt = 0,I;
  11. void BT(int i);
  12. int main()
  13. {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(0);
  16. cout.tie(0);
  17. File();
  18. int T;
  19. cin>>T;
  20. while(T--)
  21. {
  22. cin>>s>>I;
  23. BT(0);
  24. ans.clear();
  25. cnt = 0;
  26. }
  27. return 0;
  28. }
  29. void BT(int i)
  30. {
  31. if(cnt == I)return;
  32. if(ans.size()==s.size())
  33. {
  34. cnt++;
  35. if(cnt == I)cout<<ans<<endl;
  36. return;
  37. }
  38. for(int j=0;j<=ans.size();++j)
  39. {
  40. string x="";
  41. x+=s[i];
  42. ans.insert(j,x);
  43. BT(i+1);
  44. ans.erase(j,1);
  45. if(cnt == I)return;
  46. }
  47. }
  48.  
Runtime error #stdin #stdout #stderr 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure[abi:cxx11]'
  what():  basic_filebuf::underflow error reading the file: iostream error