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

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

using namespace std;

int main(void) {
  string str;
  int num;
  cin >> str;
  cin >> num;
  for (int i = 0; i < num; i++) {
    string op, temp, usiro;
    cin >> op;
    if (op == "replace") {
      int a, b;
      cin >> a >> b >> temp;
      str.replace(a, b - a + 1, temp);
    } else if (op == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(&str[a], &str[b + 1]);
    } else if (op == "print") {
      int a, b;
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main(void) {
  string str, temp;
  int a, b, num;
  cin >> str;
  cin >> num;
  for (int i = 0; i < num; i++) {
    string op;
    cin >> op;
    if (op == "replace") {
      cin >> a >> b >> temp;
      str = str.replace(a, b, temp);
    } else if (op == "reverse") {
      cin >> a >> b;
      reverse(&str[a], &str[b + 1]);
    } else if (op == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    }
  }

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

#include <iostream>
using namespace std;
int main(void) {
  string str;
  cin >> str;
  int q;
  cin >> q;

  for (int i = 0; i < q; i++) {
    string word;
    cin >> word;
    int a, b, plen;
    cin >> a >> b;
    plen = b - a + 1;

    if (word == "print") {
      cout << str.substr(a, plen) << endl;
      // cout << "str[" << str << "] print[" << str.substr(a,plen) << "]" <<
      // endl;
    } else if (word == "reverse") {
      string buf = str;
      for (int j = 0; j < plen; j++) {
        str[a + j] = buf[b - j];
      }
      // cout << "str[" << str << "] reversefrom[" << buf << "]" << endl;
    } else if (word == "replace") {
      string p;
      cin >> p;
      for (int j = 0; j < plen; j++) {
        str[a + j] = p[j];
      }
      // cout << "str[" << str << "] replaceword[" << p << "]" << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {

  string str;
  cin >> str;

  int n = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string keyword;
    cin >> keyword;

    int a, b;
    cin >> a >> b;
    string p;

    if (keyword == "print") {
      cout << str.substr(a, b + 1 - a) << endl;
    } else if (keyword == "reverse") {
      string buf = "";
      if (a > 0) {
        buf = str.substr(0, a + 1);
      }
      if (a < b) {
        for (int j = b; j >= a; j--) {
          buf += str.substr(j, 1);
        }
      }
      if (a + b < str.size()) {
        buf += str.substr(a + b + 1);
      }
      str = buf;
    } else if (keyword == "replace") {
      cin >> p;
      string buf = "";
      if (a > 0) {
        buf = str.substr(0, a);
      }
      buf += p;
      if (a + b < str.size()) {
        buf += str.substr(a + b);
      }
      str = buf;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int comand(string s) {
  if (s == "print") {
    return 1;
  } else if (s == "reverse") {
    return 2;
  } else if (s == "replace") {
    return 3;
  }
}

int main() {
  int a, b, q, num;
  string str, com;
  string temp, rep, r_str;

  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> com;
    num = comand(com);

    switch (num) {
    case 1: // print a b　a文字目からb文字目まで表示
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
      break;
    case 2: // reverse a b a文字目からb文字目まで逆順
      cin >> a >> b;
      temp = str.substr(a, b - a + 1);
      r_str = temp;
      for (int i = 0; i < temp.size(); i++) {
        r_str[i] = temp[b - a - i];
      }
      str = str.replace(a, b - a + 1, r_str);
      break;
    case 3: // replace a b rep a文字目からb文字目まで任意の文字で置換
      cin >> a >> b >> rep;
      str = str.replace(a, b - a + 1, rep);
      break;
    default:
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int comand(string s) {
  if (s == "print") {
    return 1;
  } else if (s == "reverse") {
    return 2;
  } else if (s == "replace") {
    return 3;
  }
}

int main() {
  int a, b, q, num;
  string str, com;
  string temp, rep;

  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> com;
    num = comand(com);

    switch (num) {
    case 1: // print a b　a文字目からb文字目まで表示
      cin >> a >> b;
      cout << str.substr(a, b + 1) << endl;
      break;
    case 2: // reverse a b a文字目からb文字目まで逆順
      cin >> a >> b;
      for (int i = a; i < b; i++) {
        temp[b - i] = str[i];
        str[i] = str[b - i];
        str[b - i] = temp[b - i];
      }
      break;
    case 3: // replace a b rep a文字目からb文字目まで任意の文字で置換
      cin >> a >> b >> rep;
      str = str.replace(a, b, rep);
      break;
    default:
      break;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, order, p;
  char ch;
  cin >> s;
  int n, i, a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      s.replace(a, b - a + 1, p);
    }
    if (order == "reverse") {
      cin >> a >> b;
      int left = a;
      int right = b;
      while (left < right) {
        ch = s.at(right);
        s.at(right) = s.at(left);
        s.at(left) = ch;
        right--;
        left++;
      }
    }
    if (order == "print") {
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
  }
}


Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, order, p;
  char ch;
  cin >> s;
  int n, i, a, b;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      s.replace(a, b, p);
    }
    if (order == "reverse") {
      cin >> a >> b;
      int left = a;
      int right = b;
      while (left < right) {
        ch = s.at(right);
        s.at(right) = s.at(left);
        s.at(left) = ch;
        right--;
        left++;
      }
    }
    if (order == "print") {
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string str, func, x;
  int a, b, num;
  cin >> str;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> func >> a >> b;
    // cout << x;
    if (func == "replace") {
      cin >> x;
      for (int j = 0; j < b - a + 1; j++) {
        str[j + a] = x[j];
      }
    }
    if (func == "reverse") {
      for (int j = 0; j < (int)((b - a + 1) / 2); j++) {
        char ch = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = ch;
      }
    }
    if (func == "print") {
      for (int i = 0; i < b - a + 1; i++) {
        cout << str[a + i];
      }
      cout << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string str, func, x;
  int a, b;
  while (1) {
    int num;
    cin >> str;
    cin >> num;
    for (int i = 0; i < num; i++) {
      cin >> func >> a >> b;
      // cout << x;
      if (func == "replace") {
        cin >> x;
        for (int j = 0; j < b - a + 1; j++) {
          str[j + a] = x[j];
        }
      }
      if (func == "reverse") {
        for (int j = 0; j < (int)((b - a + 1) / 2); j++) {
          char ch = str[a + j];
          str[a + j] = str[b - j];
          str[b - j] = ch;
        }
      }
      if (func == "print")
        break;
    }
    for (int i = 0; i < b - a + 1; i++) {
      cout << str[a + i];
    }
    cout << endl;
  }

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

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

int main(void) {
  string str, command, p, tmp;
  int count, a, b;
  cin >> str >> count;
  for (int i = 0; i < count; i++) {
    cin >> command;
    if (command == "replace") {
      cin >> a >> b >> p;
      for (int j = 0; j < b - a + 1; j++) {
        str[a + j] = p[j];
      }
    }
    if (command == "reverse") {
      cin >> a >> b;
      for (int j = a; j <= b; j++) {
        tmp[b - j] = str[j];
      }
      for (int j = a; j <= b; j++) {
        str[j] = tmp[j - a];
      }
    }
    if (command == "print") {
      cin >> a >> b;
      for (int j = 0; j < b - a + 1; j++) {
        cout << str[a + j];
      }
      cout << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  string str, command, p;
  int count, a, b;
  cin >> str >> count;
  for (int i = 0; i < count; i++) {
    cin >> command;
    if (command == "replace") {
      cin >> a >> b >> p;
      for (int j = a; j <= b; j++) {
        str[j] = p[j - a];
      }
    }
    if (command == "reverse") {
      cin >> a >> b;
      for (int j = a; j <= b; j++) {
        p[b - j] = str[j];
      }
      for (int j = a; j <= b; j++) {
        str[j] = p[j - a];
      }
    }
    if (command == "print") {
      cin >> a >> b;
      for (int j = a; j <= b; j++) {
        cout << str[j];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  string str;
  char order[16];
  int n;
  int a, b;
  char word[1000];

  cin >> str;
  cin >> n;

  for (int i = 0; i < n; ++i) {
    cin >> order;

    if (strstr(order, "print")) {
      cin >> a >> b;
      for (int j = a; j < b + 1; ++j) {
        cout << str[j];
      }
      cout << endl;
    } else if (strstr(order, "reverse")) {
      cin >> a >> b;
      for (int j = 0; j < (double)(b - a + 1) / 2; ++j) {
        char cpy = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = cpy;
      }
    } else if (strstr(order, "replace")) {
      cin >> a >> b >> word;
      str.replace(a, b - a + 1, word);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  string str;
  int n;
  char order[16];
  int a, b;

  getline(cin, str);
  cin >> n;
  for (int k = 0; k < n; ++k) {
    cin >> order;
    if (strstr(order, "print")) {
      cin >> a >> b;
      for (int i = 0; i < b - a + 1; ++i) {
        cout << str[a + i];
      }
      cout << endl;
    } else if (strstr(order, "reverse")) {
      cin >> a >> b;
      char copy[1000];
      for (int i = 0; i < b - a + 1; ++i) {
        copy[b - a - i] = str[a + i];
      }
      str.replace(a, b + 1, copy);
    } else if (strstr(order, "replace")) {
      char word[100];
      cin >> a >> b >> word;
      str.replace(a, b, word);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 30)

typedef long long ll;

using namespace std;

void solve() {
  string s;
  int n;

  cin >> s;
  cin >> n;

  rep(i, n) {
    string q;
    cin >> q;

    if (q == "replace") {
      int x, y;
      string ss;
      cin >> x >> y >> ss;
      s.replace(x, y - x + 1, ss);
    } else if (q == "reverse") {
      int x, y;
      cin >> x >> y;
      reverse(s.begin() + x, s.begin() + y + 1);
    } else if (q == "print") {
      int x, y;
      cin >> x >> y;
      cout << s.substr(x, y - x + 1) << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 30)

typedef long long ll;

using namespace std;

void solve() {
  string s;
  int n;

  cin >> s;
  cin >> n;

  rep(i, n) {
    string q;
    cin >> q;

    if (q == "replace") {
      int x, y;
      string ss;
      cin >> x >> y >> ss;
      s.replace(x, y, ss);
    } else if (q == "reverse") {
      int x, y;
      cin >> x >> y;
      reverse(s.begin() + x, s.begin() + (y + 1));
    } else if (q == "print") {
      int x, y;
      cin >> x >> y;
      cout << s.substr(x, y + 1) << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

string replace(string str, int a, int b, string p);
string reverse(string str, int a, int b);
void print(string str, int a, int b);

int main() {
  string str, order, p;
  int a, b, q;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      str = replace(str, a, b, p);
    } else if (order == "reverse") {
      cin >> a >> b;
      str = reverse(str, a, b);
    } else if (order == "print") {
      cin >> a >> b;
      print(str, a, b);
    }
  }
  return 0;
}

string replace(string str, int a, int b, string p) {
  string ret = str;
  for (int i = 0; i < b - a + 1; i++) {
    ret[a + i] = p[i];
  }
  return ret;
}

string reverse(string str, int a, int b) {
  string ret = str;
  for (int i = 0; i < b - a + 1; i++) {
    ret[a + i] = str[b - i];
  }
  return ret;
}

void print(string str, int a, int b) {
  string ret = str.substr(a, b - a + 1);
  cout << ret << endl;
}

Error: 0

Fixed submission:

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

string reverse(string str, int a, int b);
void print(string str, int a, int b);

int main() {
  string str, order, p;
  int a, b, q;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> p;
      str = str.replace(a, b, p);
    } else if (order == "reverse") {
      cin >> a >> b;
      str = reverse(str, a, b);
    } else if (order == "print") {
      cin >> a >> b;
      print(str, a, b);
    }
  }
  return 0;
}

string reverse(string str, int a, int b) {
  string ret = str;
  for (int i = 0; i < b - a + 1; i++) {
    ret[a + i] = str[b - i];
  }
  return ret;
}

void print(string str, int a, int b) {
  string ret = str.substr(a, b + 1);
  cout << ret << endl;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;

  for (int i = 0; i < q; i++) {
    string order;
    cin >> order;

    int a, b;
    cin >> a >> b;
    if (order == "reverse") {
      string Temp;
      for (int i = a; i <= b; i++) {
        Temp[i] = str[i];
      }
      for (int i = a; i <= b; i++) {
        str[a + b - i] = Temp[i];
      }
    }
    if (order == "replace") {
      string p;
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
    if (order == "print") {
      for (int i = a; i <= b; i++) {
        cout << str[i];
      }
      cout << endl;
    }
  }
}


Error: 0

Fixed submission:

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

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


#include <ctype.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  string gankou, ohn, mezikara, tokuteigai;
  int p, n, i, o, m, z, a, b;
  cin >> mezikara >> p;
  for (; p > 0; p = p - 1) {
    cin >> ohn >> i >> o;
    z = o - i + 1;
    if (ohn == "replace") {
      cin >> gankou;
      mezikara = mezikara.replace(i, o - i + 1, gankou);
    }
    if (ohn == "reverse") {
      char pop;
      for (a = 0; a < z / 2; a++) {
        pop = mezikara[i + a];
        mezikara[i + a] = mezikara[o - a];
        mezikara[o - a] = pop;
      }
    }
    if (ohn == "print") {
      cout << mezikara.substr(i, z) << endl;
    }
  }
  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 5)


Fixed submission:


#include <ctype.h>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void) {
  string gankou, ohn, mezikara, tokuteigai;
  int p, n, i, o, m, z, a, b;
  cin >> mezikara >> p;
  for (; p > 0; p = p - 1) {
    cin >> ohn >> i >> o;
    z = o - i + 1;
    while (1) {
      if (ohn == "replace") {
        cin >> gankou;
        mezikara = mezikara.replace(i, o - i + 1, gankou);
        break;
      }
      if (ohn == "reverse") {
        gankou = mezikara.substr(i, z);
        for (int r = 0; r < z; r++) {
          tokuteigai += gankou.substr(o, 1);
          o--;
        }
        mezikara = mezikara.replace(o, z, tokuteigai);
        tokuteigai = "";
        break;
      }
      if (ohn == "print") {
        cout << mezikara.substr(i, z) << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
  string str, ans[100], p, ex;
  int a, b, q, cou = 0;
  char c;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> ex;
    cin >> a >> b;
    if (ex == "print") {
      ans[cou] = str.substr(a, (b - a) + 1);
      cou++;
    }
    if (ex == "reverse") {
      for (int j = 0; j < (b - a + 1) / 2; j++) {
        c = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = c;
      }
    }
    if (ex == "replace") {
      cin >> p;
      str = str.replace(a, (b - a) + 1, p);
    }
  }
  for (int i = 0; i < cou; i++) {
    cout << ans[i] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
  string str, ans[100], p, ex;
  int a, b, q, cou = 0;
  char c;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> ex;
    cin >> a >> b;
    if (ex == "print") {
      ans[cou] = str.substr(a, (b - a) + 1);
      cou++;
    }
    if (ex == "reverse") {
      for (int j = 0; j < (b - a + 1) / 2; j++) {
        c = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = c;
      }
    }
    if (ex == "replace") {
      cin >> p;
      str = str.replace(a, b, p);
    }
  }
  for (int i = 0; i < cou; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  string str;
  int n;
  cin >> str;
  cin >> n;
  // iを使わないで減らすだけ
  while (n--) {
    string s;
    cin >> s;
    if (s == "print") {
      int a, b;
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (s == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
    } else {
      int a, b;
      string p;
      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 s;
  cin >> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a;
    int b, c;
    string d;
    cin >> a;
    if (a == "replace") {
      cin >> b >> c >> d;
      s.replace(b, c, d);
      // cout << s << endl;
    } else if (a == "reverse") {
      cin >> b >> c;
      reverse(&s[b], &s[c + 1]);
      // cout << s << endl;
    } else {
      string e;
      cin >> b >> c;
      e = s.substr(b, c + 1);
      cout << e << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, order;
  int q, a, b;
  cin >> str >> q;
  for (int i = 1; i <= q; i++) {
    string rev;
    cin >> order;
    if (order == "print") {
      cin >> a >> b;
      for (int j = a; j <= b; j++) {
        cout << str[j];
      }
      cout << endl;
    } else if (order == "reverse") {
      cin >> a >> b;
      for (int j = b; j >= a; j--) {
        rev += str[j];
      }
      str = str.replace(a, b - a + 1, rev);
    }
    if (order == "replace") {
      cin >> a >> b >> rev;
      str = str.replace(a, b - a + 1, rev);
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, order, rev;
  int q, a, b;
  cin >> str >> q;
  for (int i = 1; i <= 3; i++) {
    cin >> order;
    if (order == "print") {
      cin >> a >> b;
      for (int j = a; a <= b; j++) {
        cout << str[j];
      }
      cout << endl;
    } else if (order == "reverse") {
      cin >> a >> b;
      for (int j = b; b >= a; j--) {
        rev += str[j];
      }
      str = str.replace(a, b - a + 1, rev);
    }
    if (order == "replace") {
      cin >> a >> b >> rev;
      str = str.replace(a, b - a + 1, rev);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;

  string allow;

  string replacechar;

  int S, E;

  string a;

  int q;

  cin >> str;

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> allow >> S >> E;

    if (allow == "replace") {

      cin >> replacechar;

      str.replace(S, E - S + 1, replacechar);
    }
    if (allow == "reverse") {

      string B = str.substr(S, E - S + 1);

      reverse(B.begin(), B.end());

      str.replace(S, E - S + 1, B);
    }
    if (allow == "print") {

      cout << str.substr(S, E - S + 1);

      cout << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  string str;

  string allow;

  string replacechar;

  int S, E;

  string a;

  int q;

  cin >> str;

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> allow;

    if (allow == "replace") {
      cin >> S >> E;

      cin >> replacechar;

      str.replace(S, E, replacechar);
    } else if (allow == "reverse") {
      cin >> S >> E;

      int B = E / 2;

      for (int j = 0; j < B; j++) {
        a = str;
        str[j + S] = str[E - j];
        str[E - j] = a[j + S];
      }

    } else if (allow == "print") {
      cin >> S >> E;

      cout << str.substr(S, E - S + 1);

      cout << endl;
    }
  }

  return 0;
}