fork download
  1. #include <bits/stdc++.h>
  2. #define nl "\n"
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7. #ifndef ONLINE_JUDGE
  8. freopen("input.txt","r",stdin);
  9. freopen("output.txt","w",stdout);
  10. #endif
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13. cout.tie(0);
  14.  
  15.  
  16. int len,ope;
  17. cin >> len >> ope;
  18. string X;
  19. cin >> X;
  20. for(int i=0 ; i<=ope ; i++){
  21. string que;
  22. cin >> que;
  23.  
  24. if(que == "substr"){
  25. int pos1,pos2;
  26. cin >> pos1 >> pos2;
  27. int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
  28. cout << X.substr(mi-1,ma)<<nl;
  29. } else if(que == "sort"){
  30.  
  31. int pos1,pos2;
  32. cin >> pos1 >> pos2;
  33. int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
  34. sort(X.begin()+mi-1,X.begin()+ma);
  35. } else if(que == "pop_back"){
  36. X.pop_back();
  37. } else if(que == "back"){
  38. cout << X.back()<<nl;
  39. } else if(que == "reverse"){
  40. int pos1,pos2;
  41. cin >> pos1 >> pos2;
  42. pos1 -=1;
  43. int mi=min(pos1,pos2) ,ma=max(pos1,pos2);
  44. reverse(X.begin()+mi,X.begin()+ma);
  45. } else if(que == "front"){
  46. cout << X.front()<<nl;
  47. } else if(que == "push_back"){
  48. char ch;
  49. cin >> ch;
  50. X.push_back(ch);
  51. } else if(que == "print"){
  52. int pos;
  53. cin >> pos;
  54. cout << X[pos-1] <<nl;
  55. }
  56.  
  57. }
  58.  
  59.  
  60. return 0 ;
  61. }
  62.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty