fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cmath>// TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
  4. #include <vector>
  5. using namespace std ;
  6. int main() {
  7.  
  8. int n,t;
  9. cin>>n>>t;
  10. string s;
  11. cin>>s;
  12. int x,y,pos;
  13. while(t--) {
  14. string op;
  15. cin>>op;
  16. if (op=="pop_back") {
  17. s.pop_back();
  18. }
  19. else if (op=="front" )
  20.  
  21. cout<< s.front();
  22. else if (op=="back" )
  23. cout<< s.back()<<"\n";
  24. else if (op=="sort") {
  25. cin>>x>>y;
  26. if (x>y) swap(x,y);
  27. sort(s.begin()+x-1,s.begin()+y);
  28. }
  29. else if (op=="reverse") {
  30. cin>>x>>y;
  31. if (x>y)
  32. swap(x,y);
  33. reverse(s.begin()+x-1,s.begin()+y);
  34. }
  35.  
  36. else if (op=="print") {
  37. cin>>pos;
  38. cout<<s[pos-1] <<"\n";}
  39. else if (op=="substr")
  40. {cin>>x>>y;
  41. if (x>y) swap(x,y);
  42. string s1=s.substr(x-1,(y-x)+1);
  43. cout<<s1<<"\n";
  44. }
  45. else if (op=="push_back") {
  46. char c;
  47. cin>>c;
  48. s.push_back(c);
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. cout<< '\n' ;
  58.  
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. return 0;
  71. }
  72.  
  73. // TIP See CLion help at <a
  74. // href="https://w...content-available-to-author-only...s.com/help/clion/">jetbrains.com/help/clion/</a>.
  75. // Also, you can try interactive lessons for CLion by selecting
  76. // 'Help | Learn IDE Features' from the main menu.
Success #stdin #stdout 0.01s 5296KB
stdin
18 8
assiutinupperegypt
substr 1 6
sort 5 8
pop_back
back
reverse 1 6
front
push_back i
print 4
OutputCopy
assiut
p
n
s
stdout
assiut



p


n

s