Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main() {
- int n, q;
- cin >> n >> q;
- cin.ignore();
- string s;
- getline(cin, s);
- while (q--){
- string query;
- cin >> query;
- if (query == "pop_back") {
- if (n!=0) {
- s.pop_back();
- n--;
- }
- }
- else if (query == "front") {
- if (n!=0)
- cout << s[0] << endl;
- }
- else if (query == "back") {
- if (n!=0)
- cout << s[n-1] << endl;
- }
- else if (query == "sort") {
- int x, y;
- cin >> x >> y;
- sort(s.begin()+x-1, s.begin()+y);
- }
- else if (query == "reverse") {
- int x, y;
- cin >> x >> y;
- reverse(s.begin()+x-1, s.begin()+y);
- }
- else if (query == "print") {
- int x;
- cin >> x;
- cout << s[x-1] << endl;
- }
- else if (query == "substr") {
- int x, y;
- cin >> x >> y;
- if (x<=y)
- cout << s.substr(x-1, y-x+1) << endl;
- }
- else if (query == "push_back") {
- char x;
- cin >> x;
- s.push_back(x);
- n++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment