alexjercan/bugnet huggingface dataset:
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

int main(void) {
  std::string str;
  int a;
  int b;
  int q;
  std::string start = "";
  std::string sub = "";
  std::string end = "";
  std::string s = "";
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::string order;
    std::cin >> order;
    std::cin >> a >> b;
    start = str.substr(0, a);
    sub = str.substr(a, b - a + 1);
    end = str.substr(b + 1, str.size() - b);

    if (order == "replace") {
      s = "";
      std::cin >> s;
      str = start + s + end;
    } else if (order == "reverse") {
      std::reverse(sub.begin(), sub.end());
      str = start + sub + end;
    } else if (order == "print") {
      std::cout << sub << std::endl;
    } else {
    }
  }

  return EXIT_SUCCESS;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

int main(void) {
  std::string str;
  int a;
  int b;
  int q;
  std::string start = "";
  std::string sub = "";
  std::string end = "";
  std::string s = "";
  std::cin >> str >> q;

  for (int i = 0; i < q; i++) {
    std::string order;
    std::cin >> order;
    std::cin >> a >> b;
    start = str.substr(0, a);
    sub = str.substr(a, b - a + 1);
    end = str.substr(b + 1, str.size() - b);

    if (order == "replace") {
      s = "";
      std::cin >> s;
      str = start + s + end;
    } else if (order == "reverse") {
      std::reverse(sub.begin(), sub.end());
      str = start + sub + end;
    } else if (order == "print") {
      str = sub;
      std::cout << str << std::endl;
    }
  }

  return EXIT_SUCCESS;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, to) for (int i = x; i < to; i++)

string replace(string trans, int a, int b, string re) {
  rep(i, a, b + 1) { trans[i] = re[i - a]; }
  return trans;
}

string print(string trans, int a, int b) {
  string transs = trans;
  trans = trans.substr(a, b - a + 1);
  cout << trans << endl;
  return transs;
}

string reverse(string trans, int a, int b) {
  int i = a;
  int j = b;
  while (i < j) {
    swap(trans[i], trans[j]);
    i++;
    j--;
  }
  return trans;
}

int main() {
  int q, a, b;
  string str, trans;
  cin >> trans;
  cin >> q;
  rep(i, 0, q) {
    cin >> str >> a >> b;
    if (str == "print")
      print(trans, a, b);
    else if (str == "replace") {
      string re;
      cin >> re;
      trans = replace(trans, a, b, re);
    } else if (str == "reverse")
      trans = reverse(trans, a, b);
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, to) for (int i = x; i < to; i++)

int main() {
  int q, a, b;
  string str, trans;
  cin >> trans;
  cin >> q;

  rep(i, 0, q) {
    cin >> str >> a >> b;
    if (str == "print") {
      trans = trans.substr(a, b - a + 1);
      cout << trans << endl;
    } else if (str == "replace") {
      string re;
      cin >> re;
      trans = trans.substr(0, a) + re + trans.substr(b + 1);
    } else if (str == "reverse") {
      string sw = trans.substr(a, b - a + 1);
      int i = a;
      int j = b;
      while (i < j) {
        swap(sw[i], sw[j]);
        i++;
        j++;
      }
      trans = trans.substr(0, a) + sw + trans.substr(b + 1);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s1, com, s2;
  int n, a, b;

  cin >> s1 >> n;
  for (int i = 0; i < n; i++) {
    cin >> com >> a >> b;
    if (com == "print") {
      cout << s1.substr(a, b - a + 1) << endl;
    } else if (com == "replace") {
      cin >> s2;
      s1 = s1.replace(a, b - a + 1, s2);
    } else if (com == "reverse") {
      string s3 = s1.substr(a, b - a + 1);
      int m = s3.size();
      for (int k = 0; k < m; k++) {
        s1[a + k] = s3[m - 1 - k];
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string s1, com, s2;
  int n, a, b;

  cin >> s1 >> n;
  for (int i = 0; i < n; i++) {
    cin >> com >> a >> b;
    if (com == "replace") {
      cin >> s2;
      s1 = s1.replace(a, b - a + 1, s2);
    } else if (com == "reverse") {
      string s3 = s1.substr(a, b - a + 1);
      int m = s3.size();
      for (int k = 0; k < m; k++) {
        s1[a + k] = s3[m - 1 - k];
      }
    } else if (com == "print") {
      s1 = s1.substr(a, b - a + 1);
      cout << s1 << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int a, b, q, i, ii, j, R1, R2 = 0;
  int len;
  string p, str, command, r, Reverse;
  while (cin >> str, cin >> q) {
    for (i = 0; i < q; i++) {
      cin >> command;
      if (command == "print") {
        cin >> a >> b;
        cout << str.substr(a, b - a + 1) << endl;
      }
      if (command == "reverse") {
        cin >> a >> b;
        string A;
        A = str.substr(a, b - a + 1);
        reverse(A.begin(), A.end());
        /*
        len = str.substr(a,b).length();
        for(R1 = len ; 0<R1;R1--){
                r[R2] += str.substr(a,b)[R1];
                R2++;
        }
        R2 = 0;
        str = str.substr(0,a) + r + str.substr(b,str.length());
        /*
        Reverse = str.substr(a,b);
        for(R1=0,R2=str.substr(a,b).size();R1<str.substr(a,b).size(),R2>0;R1++,R2--){
                r+= Reverse[R2] ;
        }*/
        // str = str.substr(0,a) + str.substr(a,b-a+1) +
        // str.substr(b,str.substr(a,b).length());
        str.replace(a, b - a + 1, A);
      }

      if (command == "replace") {
        cin >> a >> b >> p;
        str.replace(a, b - a + 1, p);
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

//
//  main.cpp
//  ITP1-9-D
//
//  Created by h3037153 on 2017/08/29.
//  Copyright ?? 2017??´ h3037153. All rights reserved.
//
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, p, commands, Str, lenb;
  int a = 0, b = 0, q = 0, max = 0, j, jj = 0;
  int len = 0;
  while (cin >> str) {
    // cout << str.substr( 1, 2 ) << str.substr( 0, 4 ) << endl;
    cin >> q;
    for (int i = 0; i < q; i++) {
      cin >> commands;
      if (commands == "print") {
        cin >> a >> b;
        if (a == 0)
          b++;
        cout << str.substr(a, b) << endl;
      }

      else if (commands == "reverse") {
        cin >> a >> b;
        switch (str.substr(a, b).length() % 2) {
        case 0:
          for (i = a; i != j; i++) {
            for (j = b; i != j; j--) {
              swap(str[a], str[b]);
            }
          };
        case 1:
          for (i = a;; i++) {
            for (j = b; i != j - 1; j--) {
              swap(str[a], str[b]);
            }
          };
        }
        /*for(i = b; i > a; i--){
            for(j = 0; j<str.substr(a,b).length(); j++){
                Str[j] = str[i];
            }
        }
        for(i = a,j = 0; i < b, j<str.substr(a,b).length();a++ ,j++){
            str[i] = Str[j];
        } */
      }

      else if (commands == "replace") {
        cin >> a >> b >> p;
        j = 0;
        while (a <= b) {
          str[a] = p[j];
          j++;
          a++;
        }
      }
    }
  }
  // str.substr( a, b ) = p;
  return 0;
}
/*
abcde
3
replace 1 3 xyz
reverse 0 2
print 0 4
    */
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string str;
  vector<string> strs;
  int n;
  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string tmp;
      cin >> tmp;
      // str.replace(a, b, tmp);
      tmp = str.substr(0, a) + tmp + str.substr(b + 1);
      str = tmp;
    } else if (op == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      strs.push_back(str.substr(a, b - a + 1));
    }
  }

  for (int i = 0; i < strs.size(); i++)
    cout << strs[i] << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string str;
  vector<string> strs;
  int n;
  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "replace") {
      string rep;
      cin >> rep;
      str = str.replace(a, b, rep);
    } else if (op == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      strs.push_back(str.substr(a, b - a + 1));
    }
  }

  for (int i = 0; i < strs.size(); i++)
    cout << strs[i] << endl;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

// Lec09-D Transformation
#include <algorithm>
#include <iostream>
#include <string>
int main() {
  static const std::string pri = "print", rev = "reverse", rep = "replace";
  std::string str, comm, p;
  std::cin >> str;
  int q, a, b;
  for (std::cin >> q; q; q--) {
    std::cin >> comm >> a >> b;
    if (pri == comm) {
      for (; a <= b; a++)
        std::cout << str[a];
      std::cout << std::endl;
    } else if (rev == comm)
      std::reverse(str.begin() + a, str.begin() + b + 1);
    else if (rep == comm) {
      std::cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

// Lec09-D Transformation
#include <algorithm>
#include <iostream>
#include <string>
int main() {
  static const std::string pri = "print", rev = "reverse", rep = "replace";
  std::string str, comm, p;
  std::cin >> str;
  int q, a, b;
  for (std::cin >> q; q; q--) {
    std::cin >> comm >> a >> b;
    if (pri == comm) {
      for (; a <= b; a++)
        std::cout << str[a];
      std::cout << std::endl;
    } else if (rev == comm)
      std::reverse(str.begin() + a, str.begin() + b + 1);
    else if (rep == comm) {
      std::cin >> p;
      str.replace(a, b, p, 0, b - a + 1);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string str, str2;
  string str3;
  string str4;
  int n, m, d;
  cin >> str;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str2;
    cin >> m >> d;
    if (str2 == "print") {
      cout << str.substr(m, d - m + 1) << endl;
    } else if (str2 == "reverse") {
      str4 = str.substr(m, d - m + 1);
      str3 = str4;
      int wp = str4.size();
      for (int j = 0; j < wp; j++) {
        str[j + m] = str4[wp - j - 1];
      }

    } else if (str2 == "replace") {
      cin >> str3;
      str = str.replace(m, d - m + 1, str3);
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string str, str2;
  string str3 = "";
  string str4 = "";
  int n, m, d;
  cin >> str;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str2;
    cin >> m >> d;
    if (str2 == "print") {
      cout << str.substr(m, d - m + 1) << endl;
    } else if (str2 == "reverse") {
      str4 = str.substr(m, d - m + 1);
      str3 = str4;
      int wp = str4.size();
      for (int j = 0; j < wp; j++) {
        str[j] = str4[wp - j - 1];
      }

    } else if (str2 == "replace") {
      cin >> str3;
      str.replace(m, d, str3);
    }
    str3 = "";
  }

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(i, q) {
    string t;
    cin >> t;
    if (t == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (t == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (t == "replace") {
      int a, b;
      string p;
      cin >> a >> b >> p;
      s.replace(a, b - a + 1, p);
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  rep(i, q) {
    string t;
    cin >> t;
    if (t == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (t == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (t == "replace") {
      int a, b;
      string p;
      cin >> a >> b >> p;
      s.replace(a, b, p);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main(void) {

  int number;
  string str;
  cin >> str >> number;

  for (int i = 0; i < number; i++) {
    string com;
    cin >> com;

    if (com == "replace") {
      int n1, n2;
      string str2;
      cin >> n1 >> n2 >> str2;
      str.replace(n1, n2 - n1 + 1, str2);
    } else if (com == "reverse") {
      int n1, n2;
      string str_2;
      str_2 = str;
      cin >> n1 >> n2;
      for (int j = n1; j <= n2; j++) {
        str[j] = str_2[n2 + n1 - j];
      }
    } else if (com == "print") {
      int n1, n2;
      cin >> n1 >> n2;
      cout << str.substr(n1, n2 - n1 + 1) << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main(void) {

  int number;
  string str;
  cin >> str >> number;

  for (int i = 0; i < number; i++) {
    string com;
    cin >> com;

    if (com == "replace") {
      int n1, n2;
      string str2;
      cin >> n1 >> n2 >> str2;
      str.replace(n1, n2, str2);
    } else if (com == "reverse") {
      int n1, n2;
      string str_2;
      str_2 = str;
      cin >> n1 >> n2;
      for (int j = n1; j <= n2; j++) {
        str[j] = str_2[n2 + n1 - j];
      }
    } else if (com == "print") {
      int n1, n2;
      cin >> n1 >> n2;
      for (int j = n1; j <= n2; j++)
        cout << str[j];
      cout << endl;
    }
  }

  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

int main() {
  char str[1001];
  char com[8];
  int l = 0;
  int a, b;
  int q;
  char c;
  scanf("%s", &str);

  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", &com, &a, &b);
    if (com[2] == 'i') {
      for (int i = a; i <= b; i++) {
        printf("%c", str[i]);
      }
      printf("\\n");
    } else if (com[2] == 'v') {
      char t;
      for (int i = 0; i < ((b - a + 1) / 2); i++) {
        t = str[a + i];
        str[a + i] = str[b - i];
        str[b - i] = t;
      }
    } else {
      char r[1001];
      scanf("%s", &r);
      for (int j = a; j <= b; j++) {
        str[j] = r[j - a];
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>

int main() {
  char str[1001];
  char com[8];
  int l = 0;
  int a, b;
  int q;
  char c;
  scanf("%s", &str);

  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", &com, &a, &b);
    if (com[2] == 'i') {
      for (int i = a; i <= b; i++) {
        printf("%c", str[i]);
      }
      printf("\\n");
    } else if (com[2] == 'v') {
      char t;
      for (int i = 0; i < ((b - a + 1) / 2); i++) {
        t = str[a + i];
        str[a + i] = str[b - i];
        str[b - i] = t;
      }
    } else {
      char r[100];
      scanf("%s", &r);
      for (int j = a; j <= b; j++) {
        str[j] = r[j - a];
      }
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>

using namespace std;

void print(char str[], int a, int b) {
  for (int i = a; i <= b; i++)
    printf("%c", str[i]);
  printf("\\n");
}

void replace(char str[], char p[], int a, int b) {
  int p_length = b - a + 1;
  for (int i = 0; i < p_length; i++)
    str[a + i] = p[i];
}

void reverse(char str[], int a, int b) {
  int left = a, right = b;
  while (left < right) {
    swap(str[left++], str[right--]);
  }
}

int main() {
  char str[1001], p[1001], order[8];
  int q, a, b;
  scanf("%s", str);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", order, &a, &b);
    switch (order[2]) {
    case 'i':
      print(str, a, b);
      break;
    case 'v':
      reverse(str, a, b);
      break;
    case 'p':
      scanf("%s", p);
      replace(str, p, a, b);
      break;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <stdio.h>

using namespace std;

void print(char str[], int a, int b) {
  for (int i = a; i <= b; i++)
    printf("%c", str[i]);
  printf("\\n");
}

void replace(char str[], char p[], int a, int b) {
  int p_length = b - a + 1;
  for (int i = 0; i < p_length; i++)
    str[a + i] = p[i];
}

void reverse(char str[], int a, int b) {
  int left = a, right = b;
  while (left < right) {
    swap(str[left++], str[right--]);
  }
}

int main() {
  char str[1001], p[101], order[8];
  int q, a, b;
  scanf("%s", str);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %d %d", order, &a, &b);
    switch (order[2]) {
    case 'i':
      print(str, a, b);
      break;
    case 'v':
      reverse(str, a, b);
      break;
    case 'p':
      scanf("%s", p);
      replace(str, p, a, b);
      break;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int q, i;
  cin >> q;
  string s1, s2;
  int a, b;
  for (i = 0; i < q; i++) {
    // cout << str << endl;
    cin >> s1 >> a >> b;
    if (s1 == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (s1 == "reverse") {
      string s3 = str.substr(a, b - a + 1);
      reverse(s3.begin(), s3.end());
      str = str.substr(0, a) + s3 + str.substr(b + 1, str.size() - a - 1);
    } else {
      cin >> s2;
      str = str.substr(0, a) + s2 + str.substr(b + 1, str.size() - a - 1);
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int q, i;
  cin >> q;
  string s1, s2;
  int a, b;
  for (i = 0; i < q; i++) {
    // cout << str << endl;
    cin >> s1 >> a >> b;
    if (s1 == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (s1 == "reverse") {
      string s3 = str.substr(a, b - a + 1);
      reverse(s3.begin(), s3.end());
      str = str.substr(0, a) + s3 + str.substr(b + 1, str.size() - a - b);
    } else {
      cin >> s2;
      str = str.substr(0, a) + s2 + str.substr(b + 1, str.size() - a - b);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
void PRINT(std::string str) {
  int a, b;
  std::cin >> a >> b;
  str = str.substr(a, b - a + 1);
  std::cout << str << std::endl;
}
void REVERSE(std::string &str) {
  int a, b;
  std::cin >> a >> b;
  std::string CopySTR = str;
  for (unsigned int i = 0; i <= b - a; ++i) {
    str[a + i] = CopySTR[b - i];
  }
}
void REPLACE(std::string &str) {
  int a, b;
  std::string q;
  std::cin >> a >> b >> q;
  str = str.erase(a, b - a + 1);
  str = str.insert(a, q);
}
int main(void) {
  std::string str;
  std::cin >> str;
  int NumberCOMAND;
  std::cin >> NumberCOMAND;
  for (int i = 0; i < NumberCOMAND; ++i) {
    std::string COMAND;
    std::cin >> COMAND;
    if (COMAND == "print") {
      PRINT(str);
    } else if (COMAND == "reverse") {
      REVERSE(str);
      //	std::cout << str << std::endl;
    } else if (COMAND == "replace") {
      REPLACE(str);
      // std::cout << str << std::endl;
    }
  }
  // system("pause");
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
void PRINT(std::string &str) {
  int a, b;
  std::cin >> a >> b;
  str = str.substr(a, b - a + 1);
}
void REVERSE(std::string &str) {
  int a, b;
  std::cin >> a >> b;
  std::string CopySTR = str;
  for (unsigned int i = 0; i <= b - a; ++i) {
    str[a + i] = CopySTR[b - i];
  }
}
void REPLACE(std::string &str) {
  int a, b;
  std::string q;
  std::cin >> a >> b >> q;
  str = str.erase(a, b - a + 1);
  str = str.insert(a, q);
}
int main(void) {
  std::string str;
  std::cin >> str;
  int NumberCOMAND;
  std::cin >> NumberCOMAND;
  for (int i = 0; i < NumberCOMAND; ++i) {
    std::string COMAND;
    std::cin >> COMAND;
    if (COMAND == "print") {
      PRINT(str);
      std::cout << str << std::endl;
    } else if (COMAND == "reverse") {
      REVERSE(str);
      //	std::cout << str << std::endl;
    } else if (COMAND == "replace") {
      REPLACE(str);
      // std::cout << str << std::endl;
    }
  }
  //	system("pause");
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  string str, s1;
  string order;
  int a, b;
  cin >> str;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> order >> a >> b;
    if (order == "print") {
      for (int i = a; i <= b; i++) {
        cout << str[i];
      }
      cout << "\\n";
    } else if (order == "reverse") {
      for (int i = a, j = b; i < j; i++, j--)
        swap(str[i], str[j]);
    } else if (order == "replace") {
      cin >> s1;
      str.replace(a, b - a + 1, s1);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  string str, s1;
  string order;
  int a, b;
  cin >> str;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> order >> a >> b;
    if (order == "print") {
      for (int i = a; i <= b; i++) {
        cout << str[i];
      }
      cout << "\\n";
    } else if (order == "reverse") {
      for (int i = a, j = b; i < j; i++, j--)
        swap(str[i], str[j]);
    } else if (order == "replace") {
      cin >> s1;
      str.replace(a, b, s1);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {

  string str;
  int a, b;
  string p;
  string command;
  int q;

  cin >> str >> q;
  for (int i = 0; i < q; ++i) {
    cin >> command;
    if (command == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (command == "reverse") {
      cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      cin >> a >> b >> p;
      str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  string temp;
  int a, b;
  string p;
  int q;
  string s;

  cin >> str >> q;
  for (int i = 0; i < q; ++i) {
    cin >> temp;
    if (temp == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (temp == "reverse") {
      cin >> a >> b;
      s = str;
      for (int i = 0; i < b - a + 1; ++i) {
        str[b - i] = s[a + i];
      }
    } else {
      cin >> a >> b >> p;
      str.erase(str.begin() + a, str.begin() + a + b);
      for (int i = 0; i < p.size(); ++i) {
        str.insert(str.begin() + a + i, p[i]);
      }
    }
  }
  return 0;
}