Advertisement
Zeinab_Hamdy

Untitled

Aug 10th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<limits.h>
  4. #include<cmath>
  5. #include<string>
  6. #define ll long long
  7. using namespace std;
  8. int main(){
  9. ll n,tests;
  10. cin>>n>>tests;
  11. string s; cin>>s;
  12. while(tests--){
  13.     string t; cin>>t;
  14.     if(t=="pop_back")
  15.         s.pop_back();
  16.     else if(t=="front")
  17.     cout<<s.front()<<'\n';
  18.     else if(t=="back")
  19.     cout<<s.back()<<"\n";
  20.     else if(t=="sort"){
  21.         ll a,b; cin>>a>>b;
  22.         sort(s.begin()+min(a,b)-1,s.begin()+max(a,b));
  23.     }else if(t=="reverse"){
  24.         ll a,b; cin>>a>>b;
  25.         reverse(s.begin()+min(a,b)-1,s.begin()+max(a,b));
  26.     }else if(t=="print"){
  27.         ll num; cin>>num;
  28.         cout<<s[num-1]<<"\n";
  29.     }else if(t=="substr"){
  30.         ll a,b; cin>>a>>b;
  31.         for(int i=min(a,b)-1;i<=max(a,b)-1;i++)
  32.         cout<<s[i];
  33.         cout<<"\n";
  34.     }else if(t=="push_back"){
  35.         char ch; cin>>ch;
  36.         s.push_back(ch);
  37.        
  38.     }
  39. }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement