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. cout << X.substr(pos1-1,pos2)<<nl;
  28. } else if(que == "sort"){
  29.  
  30. int pos1,pos2;
  31. cin >> pos1 >> pos2;
  32. sort(X.begin()+pos1-1,X.begin()+pos2);
  33. } else if(que == "pop_back"){
  34. X.pop_back();
  35. } else if(que == "back"){
  36. cout << X.back()<<nl;
  37. } else if(que == "reverse"){
  38. int pos1,pos2;
  39. cin >> pos1 >> pos2;
  40. pos1 -=1;
  41. reverse(X.begin()+pos1,X.begin()+pos2);
  42. } else if(que == "front"){
  43. cout << X.front()<<nl;
  44. } else if(que == "push_back"){
  45. char ch;
  46. cin >> ch;
  47. X.push_back(ch);
  48. } else if(que == "print"){
  49. int pos;
  50. cin >> pos;
  51. cout << X[pos-1] <<nl;
  52. }
  53.  
  54. }
  55.  
  56.  
  57. return 0 ;
  58. }
  59.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty