Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<limits.h>
- #include<cmath>
- #include<string>
- #define ll long long
- using namespace std;
- int main(){
- ll n,tests;
- cin>>n>>tests;
- string s; cin>>s;
- while(tests--){
- string t; cin>>t;
- if(t=="pop_back")
- s.pop_back();
- else if(t=="front")
- cout<<s.front()<<'\n';
- else if(t=="back")
- cout<<s.back()<<"\n";
- else if(t=="sort"){
- ll a,b; cin>>a>>b;
- sort(s.begin()+min(a,b)-1,s.begin()+max(a,b));
- }else if(t=="reverse"){
- ll a,b; cin>>a>>b;
- reverse(s.begin()+min(a,b)-1,s.begin()+max(a,b));
- }else if(t=="print"){
- ll num; cin>>num;
- cout<<s[num-1]<<"\n";
- }else if(t=="substr"){
- ll a,b; cin>>a>>b;
- for(int i=min(a,b)-1;i<=max(a,b)-1;i++)
- cout<<s[i];
- cout<<"\n";
- }else if(t=="push_back"){
- char ch; cin>>ch;
- s.push_back(ch);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement