String Functions problem needs help...

Правка en1, от Night_Lord, 2022-03-06 09:28:08

Runtime error on test 2. but I did everything as the problem statement says ...

Problem : https://codeforces.net/group/MWSDmqGsZm/contest/219856/problem/L

int n, m; cin >> n >> m;
    string s; cin >> s;
    while (m--) {
        string op; cin >> op;
        if (op == "substr") {
            int l, r; cin >> l >> r;
            l--, r--;
            cout << s.substr(l, r + 1) << '\n';
        } else if (op == "sort") {
            int l, r; cin >> l >> r;
            l--, r--;
            sort(s.begin() + l, s.begin() + r + 1);
        } else if (op == "pop_back") {
            s.pop_back();
        } else if (op == "back") {
            cout << s.back() << '\n';
        } else if (op == "reverse") {
            int l, r; cin >> l >> r;
            l--, r--;
            reverse(s.begin() + l, s.begin() + r + 1);
        } else if (op == "front") {
            cout << s.front() << '\n';
        } else if (op == "push_back") {
            char i; cin >> i;
            s.push_back(i);
        } else {
            int pos; cin >> pos;
            pos--;
            cout << s[pos] << '\n';
        }
    }

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Night_Lord 2022-03-06 09:28:08 1205 Initial revision (published)