lina_os

Untitled

Nov 21st, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5. int main() {
  6. int n, q;
  7. cin >> n >> q;
  8. cin.ignore();
  9. string s;
  10. getline(cin, s);
  11. while (q--){
  12. string query;
  13. cin >> query;
  14. if (query == "pop_back") {
  15. if (n!=0) {
  16. s.pop_back();
  17. n--;
  18. }
  19. }
  20. else if (query == "front") {
  21. if (n!=0)
  22. cout << s[0] << endl;
  23. }
  24. else if (query == "back") {
  25. if (n!=0)
  26. cout << s[n-1] << endl;
  27. }
  28. else if (query == "sort") {
  29. int x, y;
  30. cin >> x >> y;
  31. sort(s.begin()+x-1, s.begin()+y);
  32. }
  33. else if (query == "reverse") {
  34. int x, y;
  35. cin >> x >> y;
  36. reverse(s.begin()+x-1, s.begin()+y);
  37. }
  38. else if (query == "print") {
  39. int x;
  40. cin >> x;
  41. cout << s[x-1] << endl;
  42. }
  43. else if (query == "substr") {
  44. int x, y;
  45. cin >> x >> y;
  46. if (x<=y)
  47. cout << s.substr(x-1, y-x+1) << endl;
  48. }
  49. else if (query == "push_back") {
  50. char x;
  51. cin >> x;
  52. s.push_back(x);
  53. n++;
  54. }
  55. }
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment