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

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  char str_c[1001];
  scanf("%s", str_c);
  string str(str_c);

  int num_q;
  scanf("%d", &num_q);

  int i, j;
  char cmd_c[100];
  string cmd;
  int a, b;
  char repl_c[1001];
  string repl;
  string line;
  i = 0;
  string new_str;
  while (1) {
    getline(cin, line);
    if (line == "")
      continue;
    else
      i++;

    sscanf(line.c_str(), "%s", cmd_c);
    cmd = string(cmd_c);
    if (cmd == "replace") {
      sscanf(line.c_str(), "%s %d %d %s", cmd_c, &a, &b, repl_c);
      repl = string(repl_c);
      str.replace(a, b - a + 1, repl);
    } else {
      sscanf(line.c_str(), "%s %d %d", cmd_c, &a, &b);
      if (cmd == "reverse") {
        new_str = string(str);
        for (j = a; j <= b; j++) {
          new_str[j] = str[b + a - j];
        }
        str = string(new_str);
        // printf("-> %s\\n", str.c_str());
      } else {
        cout << str.substr(a, b - a + 1) << endl;
      }
    }
    if (i >= num_q) {
      break;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  char str_c[1001];
  scanf("%s", str_c);
  string str(str_c);

  int num_q;
  scanf("%d", &num_q);

  int i, j;
  char cmd_c[100];
  string cmd;
  int a, b;
  char repl_c[1001];
  string repl;
  string line;
  i = 0;
  string new_str;
  while (1) {
    getline(cin, line);
    if (line == "")
      continue;
    else
      i++;

    sscanf(line.c_str(), "%s", cmd_c);
    cmd = string(cmd_c);
    if (cmd == "replace") {
      sscanf(line.c_str(), "%s %d %d %s", cmd_c, &a, &b, repl_c);
      repl = string(repl_c);
      str.replace(a, b, repl);
    } else {
      sscanf(line.c_str(), "%s %d %d", cmd_c, &a, &b);
      if (cmd == "reverse") {
        new_str = string(str);
        for (j = a; j <= b; j++) {
          new_str[j] = str[b + a - j];
        }
        str = string(new_str);
        // printf("-> %s\\n", str.c_str());
      } else {
        cout << str.substr(a, b - a + 1) << endl;
      }
    }
    if (i >= num_q) {
      break;
    }
  }

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

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

int main() {
  int a, b;
  string which, p;

  string str;
  int y;

  cin >> str;
  cin >> y;

  for (int i = 0; i < y; i++) {
    cin >> which >> a >> b;
    if (which == "print")
      cout << str.substr(a, b - a + 1) << endl;
    else if (which == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else if (which == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int i = 0; i < n; i++) {
        str[a + i] = tmp[n - i - 1];
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int a, b;
  string which, p;

  string str;
  int y;

  cin >> str;
  cin >> y;

  for (int i = 0; i < y; i++) {
    cin >> which >> a >> b;
    if (which == "print") {
      str = str.substr(a, b - a + 1);
      cout << str << endl;
    } else if (which == "replace") {
      cin >> p;
      str = str.replace(a, b - a + 1, p);
    } else if (which == "reverse") {
      string tmp = str.substr(a, b - a + 1);
      int n = tmp.size();
      for (int i = 0; i < n; i++) {
        str[a + i] = tmp[n - i - 1];
      }
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string op;
    cin >> op;

    if (op == "replace") {

      int a, b;
      string repstr;
      cin >> a >> b >> repstr;
      auto it = str.begin() + a;
      for (int j = 0; j <= b - a; j++) {
        *it++ = repstr[j];
      }

    } else if (op == "reverse") {

      int a, b;
      cin >> a >> b;
      string str2 = str;
      auto it = str.begin() + a;
      auto it2 = str2.begin() + b;
      for (int j = 0; j <= b - a; j++) {
        *it++ = *it2--;
      }

    } else if (op == "print") {
      int a, b;
      cin >> a >> b;
      auto it = str.begin() + a;
      for (int j = 0; j <= b - a; j++) {
        cout << *it++;
      }
      cout << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
using namespace std;

int main() {

  string str;
  int q;

  cin >> str;
  cin >> q;
  int a, b;
  rep(i, 0, q) {
    string order;
    cin >> order >> a >> b;
    string temp;
    if (order == "replace") {
      cin >> temp;
      str.replace(a, b, temp);
    } else if (order == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (order == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }

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

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

using namespace std;

int main() {
  string str, o, p, m, str2;
  int i, q, a, b, j, x, c;
  cin >> str >> q;
  for (i = 0; i < q; i++) {
    cin >> o;
    if (o == "print") {
      cin >> a >> b;
      for (j = a; j <= b; j++)
        cout << str[j];
      cout << endl;
    } else if (o == "reverse") {
      cin >> a >> b;
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (o == "replace") {
      cin >> a >> b >> p;
      str.replace(a, b - a + 1, p);
    }
  }
}

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


Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str, o, p, s, m;
  char str2[1000];
  int i, q, a, b, j, x, c;
  cin >> str >> q;
  for (i = 0; i < q; i++) {
    cin >> o;
    if (o == "print") {
      cin >> a >> b;
      for (j = a; j <= b; j++)
        cout << str[j];
      cout << endl;
    } else if (o == "reverse") {
      cin >> a >> b;
      c = b;
      x = b - a + 1;
      m.erase(str.size());
      for (j = 0; j < x; j++) {
        str2[j] = str[c];
        c--;
      }
      for (j = 0; j < a; j++) {
        if (j == 0) {
          m = str[j];
        } else if (j != 0)
          m += str[j];
      }
      for (j = 0; j < x; j++) {
        m += str2[j];
      }
      for (j = b + 1; j <= str.size(); j++) {
        m += str[j];
      }
      str = m;
    } else if (o == "replace") {
      cin >> a >> b >> p;
      s.erase(str.size());
      for (j = 0; j < a; j++) {
        if (j == 0)
          s = str[j];
        else if (j != 0)
          s += str[j];
      }
      s += p;
      for (j = b + 1; j <= str.size(); j++) {
        s += str[j];
      }
      str = s;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str1, str2;
  string command;
  int a, b;
  int q;
  int i, j, k;

  cin >> str1 >> q;

  for (i = 0; i < q; i++) {
    cin >> command;
    if (command == "replace") {
      cin >> a >> b >> str2;
      k = 0;
      for (j = a; j <= b; j++) {
        str1[j] = str2[k];
        k++;
      }
    } else if (command == "reverse") {
      cin >> a >> b;
      k = b - a;
      str2 = str1.substr(a, b - a + 1);
      for (j = a; j <= b; j++) {
        str1[j] = str2[k];
        k--;
      }
    } else if (command == "print") {
      cin >> a >> b;
      str2 = str1.substr(a, b - a + 1);
      cout << str2 << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string str1, str2;
  string command;
  int a, b;
  int q;
  int i, j, k;

  cin >> str1 >> q;

  for (i = 0; i < q; i++) {
    cin >> command;
    if (command == "replace") {
      cin >> a >> b >> str2;
      k = 0;
      for (j = a; j <= b; j++) {
        str1[j] = str2[k];
        k++;
      }
    } else if (command == "reverse") {
      cin >> a >> b;
      k = 0;
      for (j = a; j <= b; j++) {
        str2[k] = str1[j];
        k++;
      }
      for (j = a; j <= b; j++) {
        str1[j] = str2[k - 1];
        k--;
      }
    } else if (command == "print") {
      cin >> a >> b;
      for (j = a; j <= b; j++) {
        cout << str1[j];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
int main() {
  int n, a, b;
  std::string text, mei, oki, str;
  std::cin >> text >> n;
  for (int tes = 0; tes < n; tes++) {
    std::cin >> mei;
    if (mei == "print") {
      std::cin >> a >> b;
      str = text.substr(a, b - a + 1);
      std::cout << str << std::endl;
    }
    if (mei == "replace") {
      std::cin >> a >> b >> oki;
      text = text.replace(a, b - a + 1, oki);
    }
    if (mei == "reverse") {
      std::cin >> a >> b;
      std::reverse(text.begin() + a, text.begin() + b + 1);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int a, b, m;
  std::string str, str2, mei, p;
  std::cin >> str >> m;
  for (int n = 0; n < m; n++) {
    std::cin >> mei;
    if (mei == "print") {
      std::cin >> a >> b;
      std::cout << str.substr(a, b + 1) << std::endl;
    }
    if (mei == "reverse") {
      std::cin >> a >> b;
      std::reverse(str.begin() + a, str.begin() + b + 1);
    }
    if (mei == "replace") {
      std::cin >> a >> b >> p;
      str.erase(a, b);
      str.insert(a, p);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, m, p, k, k2, k3[1000];
  int a, b, q, z = 0, j, l;
  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> m >> a >> b;
    if (m == "replace") {
      cin >> p;
      str.replace(a, p.size(), p);
    }
    if (m == "reverse") {
      k = str.substr(a, b - a + 1);
      k2 = k;
      l = 0;
      for (j = k.size() - 1; j >= 0; j--) {
        k2[l] = k[j];
        l = l + 1;
      }
      str.replace(a, k2.size(), k2);
    }
    if (m == "print") {
      if (a == 0 && b == str.size() - 1) {
        k3[z] = str;
      } else if (a == 0 && b == 0) {
        k3[z] = str[0];
      } else {
        k3[z] = str.substr(a, b - a + 1);
      }
      z = z + 1;
    }
  }
  for (int w = 0; w < z; w++) {
    cout << k3[w] << endl;
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, m, p, k, k2, k3[1000];
  int a, b, q, l = 0, z = 0, j;
  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> m >> a >> b;
    if (m == "replace") {
      cin >> p;
      str.replace(a, p.size(), p);
    }
    if (m == "reverse") {
      k = str.substr(a, b + 1);
      k2 = k;
      for (j = k.size() - 1; j >= 0; j--) {
        k2[l] = k[j];
        l = l + 1;
      }
      str.replace(a, k2.size(), k2);
    }
    if (m == "print") {
      k3[z] = str.substr(a, b + 1);
      z = z + 1;
    }
  }
  for (int w = 0; w < z; w++) {
    cout << k3[w] << endl;
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

// strのa文字目からb文字目までを出力する
void print(string str, int a, int b) {
  for (int i = a; i <= b; i++) {
    cout << str[i];
  }
  cout << endl;
}

// strのa文字目からb文字目までを逆順にする
void reverse(string &str, int a, int b) {
  for (int i = 0; i < (b - a + 1) / 2; i++) {
    char tmp = str[a + i];
    str[a + i] = str[b - i];
    str[b - i] = tmp;
  }
}

// strのa文字目からb文字目までをpに置き換える
void replace(string &str, int a, int b, string p) {
  str.replace(a, b - a + 1, p);
}

int main(void) {
  string str;         // 入力文字列
  string op;          // 命令
  string replace_str; // 置き換え文字列

  int op_num; // 命令数
  int a, b;   // 対象範囲

  // 操作する文字列を入力
  cin >> str;

  // 命令数を入力
  cin >> op_num;

  for (int i = 0; i < op_num; i++) {
    // 命令を入力
    cin >> op;
    if (op == "print") // print命令の場合
    {
      cin >> a >> b;
      print(str, a, b);
    } else if (op == "reverse") // reverse命令の場合
    {
      cin >> a >> b;
      reverse(str, a, b);
    } else if (op == "replace") // replace命令の場合
    {
      cin >> a >> b >> replace_str;
      replace(str, a, b, replace_str);
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

// strのa文字目からb文字目までを出力する
void print(string str, int a, int b) {
  for (int i = a; i <= b; i++) {
    cout << str[i];
  }
  cout << endl;
}

// strのa文字目からb 文字目までを逆順にする
void reverse(string &str, int a, int b) {
  for (int i = a; i < b; i++) {
    char tmp = str[i];
    str[i] = str[b - i];
    str[b - i] = tmp;
  }
}

// strのa文字目からb文字目までをpに置き換える
void replace(string &str, int a, int b, string p) { str.replace(a, b, p); }

int main(void) {
  string str;         // 入力文字列
  string op;          // 命令
  string replace_str; // 置き換え文字列

  int op_num; // 命令数
  int a, b;   // 対象範囲

  // 操作する文字列を入力
  cin >> str;

  // 命令数を入力
  cin >> op_num;

  for (int i = 0; i < op_num; i++) {
    // 命令を入力
    cin >> op;
    if (op == "print") // print命令の場合
    {
      cin >> a >> b;
      print(str, a, b);
    } else if (op == "reverse") // reverse命令の場合
    {
      cin >> a >> b;
      reverse(str, a, b);
    } else if (op == "replace") // replace命令の場合
    {
      cin >> a >> b >> replace_str;
      replace(str, a, b, replace_str);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  string str, cmd, arg2;
  int n, arg0, arg1;

  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    cin >> cmd >> arg0 >> arg1;
    if (cmd == "print") {
      cout << str.substr(arg0, arg1 - arg0 + 1) << endl;
      continue;
    }
    if (cmd == "reverse") {
      string tmp1 = str.substr(0, arg0);
      string rev = str.substr(arg0, arg1 - arg0 + 1);
      string tmp2 = str.substr(arg1 + 1, str.size() - arg1);
      char tmp;
      int revSize = rev.size();
      for (int i = 0; i < revSize / 2; i++) {
        tmp = rev[i];
        rev[i] = rev[revSize - i - 1];
        rev[revSize - i - 1] = tmp;
      }
      str = tmp1 + rev + tmp2;
    }
    if (cmd == "replace") {
      cin >> arg2;
      string tmp1 = str.substr(0, arg0);
      string tmp2 = str.substr(arg1 + 1, str.size() - arg1);
      str = tmp1 + arg2 + tmp2;
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  string str, cmd, arg2;
  int n, arg0, arg1;

  cin >> str >> n;

  for (int i = 0; i < n; i++) {
    cin >> cmd >> arg0 >> arg1;
    if (cmd == "print") {
      cout << str.substr(arg0, arg1 - arg0 + 1) << endl;
      continue;
    }
    if (cmd == "reverse") {
      string tmp1 = str.substr(0, arg0);
      string rev = str.substr(arg0, arg1 - arg0 + 1);
      string tmp2 = str.substr(arg1 - arg0 + 1, str.size() - arg1 + arg0 - 1);
      char tmp;
      int revSize = rev.size();
      for (int i = 0; i < revSize / 2; i++) {
        tmp = rev[i];
        rev[i] = rev[revSize - i - 1];
        rev[revSize - i - 1] = tmp;
      }
      str = tmp1 + rev + tmp2;
    }
    if (cmd == "replace") {
      cin >> arg2;
      str.replace(arg0, arg1, arg2);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  string str, W, p;
  long long int q, a, b;
  cin >> str >> q;
  REP(i, q) {
    cin >> W >> a >> b;
    if (W == "print") {
      string c(str, a, b - a + 1);
      cout << c << "\\n";
    } else if (W == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (W == "replace") {
      cin >> p;
      str.replace(a, b - a + 1, p);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main() {
  string str, W, p;
  long long int q, a, b;
  cin >> str >> q;
  REP(i, q) {
    cin >> W >> a >> b;
    if (W == "print") {
      string c(str, a, b - a + 1);
      cout << c << "\\n";
    } else if (W == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (W == "replace") {
      cin >> p;
      str.replace(a, b, p);
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
int main() {
  std::string s, op;
  std::cin >> s;
  int q;
  std::cin >> q; // skip
  int a, b;
  while (std::cin >> op >> a >> b) {
    if (op == "print") {
      std::cout << s.substr(a, b - a + 1) << std::endl;
    } else if (op == "reverse") {
      std::reverse(s.begin() + a, s.begin() + b + 1);
    } else {
      std::string p;
      std::cin >> p;
      s.replace(a, b - a + 1, p);
    }
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
int main() {
  std::string s, op;
  std::cin >> s;
  int q;
  std::cin >> q; // skip
  int a, b;
  while (std::cin >> op >> a >> b) {
    if (op == "print") {
      std::cout << s.substr(a, b + 1) << std::endl;
    } else if (op == "reverse") {
      std::reverse(s.begin() + a, s.begin() + b + 1);
    } else {
      std::string p;
      std::cin >> p;
      s.replace(a, b, p);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string str, moji, m;
  int q = 0;
  cin >> str;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a = 0, b = 0;
    cin >> moji >> a >> b;
    if (moji == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (moji == "reverse") {
      string str2 = str.substr(a, b - a + 1);
      reverse(str2.begin(), str2.end());
      str = str.replace(a, b - a + 1, str2);
    } else if (moji == "replace") {
      cin >> m;
      str = str.replace(a, b - a + 1, m);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

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

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
string baka(int x, int y, string z, string a) {
  string sakurai;
  string satou;
  string huuta;
  for (int i = 0; i < x; i++) {
    sakurai += a.at(i);
  }
  for (int i = y + 1; i < a.size(); i++) {
    satou += a.at(i);
  }
  huuta += sakurai;
  huuta += z;
  huuta += satou;

  return huuta;
}
string aho(int b, int c, string x) {
  string eziri;
  string syouma;
  string s;
  string huuta;
  for (int i = 0; i < b; i++) {
    eziri += x.at(i);
  }
  for (int i = c + 1; i < x.size(); i++) {
    syouma += x.at(i);
  }
  for (int i = b; i < c + 1; i++) {
    if (i >= b && i <= c + 1)
      s += x.at(i);
  }
  reverse(s.begin(), s.end());
  huuta += eziri;
  huuta += s;
  huuta += syouma;
  return huuta;
}
int main(void) {
  int a, b = 0, c = 0;
  string x;
  string y;
  cin >> x;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> y;
    if (y == "replace") {
      string z;
      cin >> b >> c;
      cin >> z;
      x = baka(b, c, z, x);
      // cout<<x<<endl;
    } else if (y == "reverse") {
      cin >> b >> c;
      x = aho(b, c, x);
      // cout<<x<<endl;
    } else if (y == "print") {
      cin >> b >> c;
      string s;
      for (int j = 0; j < x.size(); j++) {
        if (b <= j && c >= j)
          s += x.at(j);
      }
      cout << s << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
string aho(int b, int c, string x) {
  string s;
  for (int i = 0; i < x.size(); i++) {
    if (i >= b && i <= c)
      s += x.at(i);
  }
  reverse(s.begin(), s.end());
  return s;
}
int main(void) {
  int a, b = 0, c = 0;
  string x;
  string y;
  cin >> x;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> y;
    if (y == "replace") {
      string z;
      cin >> b >> c;
      cin >> z;
      x.replace(b, c, z);
    } else if (y == "reverse") {
      cin >> b >> c;
      x.replace(b, c + 1, aho(b, c, x));
    } else if (y == "print") {
      cin >> b >> c;
      string s;
      for (int j = 0; j < x.size(); j++) {
        if (b <= j && c >= j)
          s += x.at(j);
      }
      cout << s << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <math.h>
#include <unordered_map>

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

int main() {
  string str;
  int n;

  cin >> str >> n;

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

    if (command == "replace") {
      int f, t;
      string newStr;
      cin >> f >> t >> newStr;
      str.replace(f, t - f + 1, newStr.c_str());
    } else if (command == "reverse") {
      int f, t;
      cin >> f >> t;
      reverse(str.begin() + f, str.begin() + t + 1);
    } else if (command == "print") {
      int f, t;
      cin >> f >> t;
      for (int j = f; j <= t; j++) {
        printf("%c", str[j]);
      }
      printf("\\n");
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES

#include <math.h>
#include <unordered_map>

#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)

using namespace std;

int main() {
  string str;
  int n;

  cin >> str >> n;

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

    if (command == "replace") {
      int f, t;
      string newStr;
      cin >> f >> t >> newStr;
      str.replace(f, t, newStr);
    } else if (command == "reverse") {
      int f, t;
      cin >> f >> t;
      reverse(str.begin() + f, str.begin() + t + 1);
    } else if (command == "print") {
      int f, t;
      cin >> f >> t;
      for (int j = f; j <= t; j++) {
        printf("%c", str[j]);
      }
      printf("\\n");
    }
  }
  return 0;
}