Untitled
unknown
c_cpp
a year ago
1.5 kB
8
Indexable
// #include <bits/stdc++.h>
#include <iostream>
#include<cmath>
#include<string>
#include <algorithm> 
#define ll long long
#define nl "\n"
using namespace std;
void FastIO(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#endif
}
int main(){
    FastIO();
    
    int n,q;
    cin >> n >> q;
    string word,query;
    cin >> word;
    while (q--)
    {
        cin >> query;
        if(query == "substr"){
            int s,l;
            cin >> s >> l;
            cout << word.substr(s-1,l - s + 1) << nl;
        }
        else if(query == "sort"){
            int s,l;
            cin >> s >> l;
            sort(word.begin() + (s-1), word.begin() + l);
        }
        else if(query == "pop_back"){
            word.pop_back();
        }
        else if(query == "back"){
            cout << word.back() << nl;
        }
        else if(query == "reverse"){
            int s,l;
            cin >> s >> l;
            reverse(word.begin() + (s-1), word.begin() + l);
        }
        else if(query == "front"){
            cout << word.front() << nl;
        }
        else if(query == "push_back"){
            char i;
            cin >> i;
            word.push_back(i);
        }
        else if(query == "print"){
            int index;
            cin >> index;
            cout << word[index - 1] << nl;
        }
    }
       
    return 0;
}Editor is loading...
Leave a Comment