Advertisement
Rofyda_Elghadban1

Untitled

Aug 16th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstdlib>
  6. #include <limits.h>
  7. #include <string>
  8.  
  9. #define ll long long
  10.  
  11. using namespace std;
  12. void Fast_IO();
  13. void Rofyda_Elghadban(){
  14. #ifndef ONLINE_JUDGE
  15. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  16. #endif
  17. }
  18. int main()
  19. { Rofyda_Elghadban();
  20. //Fast_IO();
  21. //freopen("input.txt","r",stdin);
  22. //freopen("output.txt","r",stdout);
  23. int size,t;
  24. cin>>size>>t;
  25. string s;
  26. cin>>s;
  27. string n;
  28. int num1,num2;
  29. while(t--){
  30. cin>>n;
  31. if(n=="pop_back"){
  32. s.pop_back();
  33. }else if(n=="front"){
  34. cout<<s.front()<<endl;
  35. }else if(n=="back"){
  36. cout<<s.back()<<endl;
  37. }else if(n=="sort"){
  38. cin>>num1>>num2;
  39. sort(s.begin()+min(num1,num2)-1,s.begin()+max(num1,num2));
  40. }else if(n=="reverse"){
  41. cin>>num1>>num2;
  42. reverse(s.begin()+min(num1,num2)-1,s.begin()+max(num1,num2));
  43. }else if(n=="print"){
  44. int pos;
  45. cin>>pos;
  46. cout<<s[pos-1];
  47. }else if(n=="substr"){
  48. cin>>num1>>num2;
  49. for(int i=min(num1,num2)-1;i<=max(num1,num2)-1;i++){
  50. cout<<s[i];
  51. }
  52. cout<<endl;
  53. }else{
  54. char ch;
  55. cin>>ch;
  56. s.push_back(ch);
  57.  
  58. }
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement