fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include<string>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8. #define all(v) (v.begin()),(v.end())
  9.  
  10. void execute_query(string& input, string query){
  11. if (query == "pop_back"){
  12. input.pop_back();
  13. }else if (query == "front"){
  14. cout << input.front() << endl;
  15. }else if (query == "back"){
  16. cout << input.back() << endl;
  17. }else if (query == "sort"){
  18. int x,y;
  19. cin >> x >> y;
  20. x = abs(x);
  21. y = abs(y);
  22. x--;
  23. sort(input.begin() + x, input.begin() + y);
  24. }else if (query == "reverse"){
  25. int x,y;
  26. cin >> x >> y;
  27. x = abs(x);
  28. y = abs(y);
  29. x--;
  30. reverse(input.begin() + x, input.begin() + y);
  31. }else if (query == "print"){
  32. int i;
  33. cin >> i;
  34. cout << input[i] << endl;
  35. }else if (query == "substr"){
  36. int x,y;
  37. cin >> x >> y;
  38. x = abs(x);
  39. y = abs(y);
  40. x--;
  41. cout << input.substr(x, y) << endl;
  42. }else if (query == "push_back"){
  43. char i;
  44. cin >> i;
  45. input.push_back(i);
  46. }
  47. }
  48.  
  49. int main() {
  50. int n, q;
  51. string input;
  52. cin >> n >> q >> input;
  53. while (q--){
  54. string query;
  55. cin >> query;
  56. execute_query(input, query);
  57. }
  58. return 0;
  59. }
Success #stdin #stdout 0.01s 5284KB
stdin
18 8
assiutinupperegypt
substr 1 6
sort 5 8
pop_back
back
reverse 1 6
front
push_back i
print 4
stdout
assiut
p
n
s