Advertisement
semsem_elazazy

L. String Functions

Feb 14th, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int main() {
  7.  int n,q;
  8.  string s;
  9.  cin>>n>>q;
  10.  cin>>s;
  11.  string qu;
  12.   int x,y;
  13.   int pos;
  14.  while(q--)
  15.  {
  16.      cin>>qu;
  17.      if(qu == "pop_back")
  18.      {
  19.          s.pop_back();
  20.      }
  21.      else if( qu =="front ")
  22.      {
  23.          cout<<s.front()<<endl;
  24.      }
  25.      else if(qu =="back")
  26.      {
  27.          cout<<s.back()<<endl;
  28.          
  29.      }
  30.      else if (qu =="sort")
  31.      {
  32.          cin>>x>>y;
  33.          sort(s.begin() + min (x,y)-1 , s.begin() + max (x,y) );
  34.      }
  35.      else if("reverse")
  36.      {
  37.          cin>>x>>y;
  38.          reverse(s.begin() + min (x,y)-1 , s.begin() + max (x,y) -1 );
  39.      }
  40.      else if("print")
  41.      {
  42.          cin>>pos;
  43.          cout<<s[pos-1]<<endl;
  44.      }
  45.      else if ("substr")
  46.      {
  47.          cin>>x>>y;
  48.          for(int i =min(x,y)-1 ;i<max(x,y)-1 ;i++)
  49.          {
  50.              cout<<s[i];
  51.          }
  52.          cout<<endl;
  53.      }
  54.      else
  55.      {
  56.          char m;
  57.          cin>>m;
  58.          s.push_back(m);
  59.      }
  60.  }
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement