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

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

int main() {
  string str;
  int q;

  cin >> str >> q;
  int len = str.size();

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

    } else if (od == "replace") {
      string p;
      cin >> a >> b >> p;
      if (a == 0) {
        str = p + str.substr(b + 1, len - b - 1);
      } else {
        str = str.substr(0, a) + p + str.substr(b + 1, len - b - 1);
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  string str;
  int q;

  cin >> str >> q;
  int len = str.size();
  // cout<<str.substr(0,-1);

  for (int i = 0; i < q; i++) {
    string od, p, tmp;
    int a, b;
    cin >> od;
    if (od == "print") {
      cin >> a >> b;
      cout << str.substr(a, b - a + 1) << endl;
    } else if (od == "reverse") {
      cin >> a >> b;
      // cout<<"reverse done"<<endl;
      string rev = str.substr(a, b - a + 1);
      // cout<<rev<<endl;
      // cout<<"aaa"<<endl;
      // int l=b-a+1;
      int l = b - a + 1;
      // cout<<l<<endl;
      for (int i = 0; i < l; i++) {
        tmp[i] = rev[l - 1 - i];
        // cout<<tmp[i];
        tmp += tmp[i];
      }
      // cout<<tmp<<endl;
      if (a == 0) {
        // cout<<"inside if"<<endl;
        // cout<<tmp<<endl;
        // cout<<str.substr(b+1, len-b-1);
        str = tmp + str.substr(b + 1, len - b - 1);
      } else {
        // cout<<"inside else"<<endl;
        str = str.substr(0, a - 1) + tmp + str.substr(b + 1, len - b - 1);
      }
      // cout<<str<<endl;
    } else if (od == "replace") {
      string p;
      cin >> a >> b >> p;
      if (a == 0) {
        str = p + str.substr(b + 1, len - b - 1);
      } else {
        str = str.substr(0, a) + p + str.substr(b + 1, len - b - 1);
      }
      // cout<<str<<endl;
    }
  }

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


#include <iostream>
#include <string>

using namespace std;

int main() {

  int a, b, c;
  string str, command, s;

  cin >> str >> c;

  for (int i = 0; i < c; i++) {

    cin >> command;

    if (command == "print") {
      cin >> a >> b;
      while (a <= b) {
        cout << str[a];
        a++;
      }
      cout << endl;
    } else if (command == "replace") {
      cin >> a >> b >> s;
      str.replace(a, b - a + 1, s);
    } else {
      cin >> a >> b;
      for (int j = 0; j < (b - a + 1) / 2; j++) {
        swap(str[a + j], str[b - j]);
      }
    }
  }

  return 0;
}


Error: -11

Fixed submission:


#include <iostream>
#include <string>

using namespace std;

int main() {

  int c, a, b;
  string str, p, order;

  cin >> str;
  cin >> c;

  for (int i = 0; i < c; i++) {

    cin >> order;
    if (order == "print") {
      cin >> a >> b;
      for (; a <= b; a++) {
        cout << str[a];
      }
      cout << endl;
    } else if (order == "reverse") {
      cin >> a >> b;
      str += str;
      for (int i = 0; a + i - 1 != b + str.size() - i; i++) {
        str[a + i] = str[b + str.size() - i];
      }
      str = str.substr(0, str.size() / 2);

    } else {
      cin >> a >> b >> p;
      str.replace(a, b - a + 1, p);
    }
  }

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

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

using namespace std;
int main() {
  string str;
  string x, y;
  int a;
  int b, c;
  cin >> str;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> x >> b >> c;
    if (x == "replace") {
      cin >> y;
      str.replace(b, c - b + 1, y);
    }
    if (x == "reverse") {
      reverse(str.begin() + b, str.begin() + c + 1);
    }
    if (x == "print") {
      cout << str.substr(b, c - b + 1) << endl;
    }
  }
}


Error: 0

Fixed submission:

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

using namespace std;
int main() {
  string str;
  string x, y;
  int a;
  int b, c;
  cin >> str;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> x >> b >> c;
    if (x == "replace") {
      cin >> y;
      str = str.replace(b, c, y);
    }
    if (x == "reverse") {
      reverse(str.begin() + b, str.begin() + c + 1);
    }
    if (x == "print") {
      cout << str.substr(b, c + 1) << endl;
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string com;
    cin >> com;
    if (com == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (com == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (com == "replace") {
      int a, b;
      cin >> a >> b;
      string word;
      cin >> word;
      s.replace(a, b - a + 1, word);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {

  string s;
  cin >> s;
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    string com;
    cin >> com;
    if (com == "print") {
      int a, b;
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << endl;
    }
    if (com == "reverse") {
      int a, b;
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    }
    if (com == "replace") {
      int a, b;
      cin >> a >> b;
      string word;
      cin >> word;
      string left = s.substr(0, a);
      string right = s.substr(a + b, s.length() - a - b);
      s = left + word + right;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  int cnt = 0, a = 0, b = 0;
  string str, cmd, p;

  cin >> str;
  cin >> cnt;

  for (int x = 0; x < cnt; x++) {
    cin >> cmd >> a >> b;

    if (cmd == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (cmd == "reverse") {
      reverse(str.begin() + a, str.begin() + b + 1);
    } else if (cmd == "replace") {
      cin >> p;
      str.replace(a, p.length(), p);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int cnt = 0, a = 0, b = 0;
  string str, cmd, p;

  cin >> str;
  cin >> cnt;

  while (cnt--) {
    cin >> cmd >> a >> b;

    if (cmd == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (cmd == "reverse") {
      for (int i = b; i = a; i--) {
        swap(str[i], str[a + (b - i)]);
      }
    } else if (cmd == "replace") {
      cin >> p;
      for (int i = a; i = b; i++) {
        str.substr(0, a - 1) + p + str.substr(b + 1, str.length());
      }
    }
  }

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

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

string revrs(string str, int a, int b) {
  int m, k, j;
  string trs;

  m = str.size();
  trs = str;
  for (k = 0; k < m; k++) {
    if (k < a || b < k)
      j = k;
    else
      j = a + b - k;
    trs[j] = str[k];
  }
  return trs;
}

string trans(string str, string c, int a, int b, string p) {
  string trs;

  trs = str;
  if (c == "reverse") {
    trs = revrs(str, a, b);
  } else if (c == "replace") {
    trs = str.erase(a, b - a + 1);
    trs = trs.insert(a, p);
  }
  return trs;
}

int main(void) {
  int n, k, m, j, a, b;
  string str, c, p, ans[1001];

  cin >> str;
  cin >> n;

  m = 0;
  for (k = 1; k <= n; k++) {
    cin >> c;
    if (c == "replace")
      cin >> a >> b >> p;
    else
      cin >> a >> b;
    if (c != "print")
      str = trans(str, c, a, b, p);
    else if (c == "print") {
      m = m + 1;
      ans[m] = str.substr(a, b - a + 1);
    }
  }

  for (j = 1; j <= m; j++) {
    cout << ans[j] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

string revrs(string str, int a, int b) {
  int m, k, j;
  string trs;

  m = str.size();
  trs = str;
  for (k = 0; k < m; k++) {
    if (k < a || b < k)
      j = k;
    else
      j = a + b - k;
    trs[j] = str[k];
  }
  return trs;
}

string trans(string str, string c, int a, int b, string p) {
  string trs;

  trs = str;
  if (c == "print")
    trs = str.substr(a, b - a + 1);
  else if (c == "reverse")
    trs = revrs(str, a, b);
  else if (c == "replace") {
    trs = str.erase(a, b);
    trs = trs.insert(a, p);
  }
  return trs;
}

int main(void) {
  int n, k, m, j, a[1001], b[1001];
  string str, c[1001], p[1001], ans[1001];

  cin >> str;
  cin >> n;

  m = 0;
  for (k = 1; k <= n; k++) {
    cin >> c[k];
    if (c[k] == "replace")
      cin >> a[k] >> b[k] >> p[k];
    else
      cin >> a[k] >> b[k];
    str = trans(str, c[k], a[k], b[k], p[k]);
    if (c[k] == "print") {
      m = m + 1;
      ans[m] = str;
    }
  }

  for (j = 1; j <= m; j++) {
    cout << ans[j] << endl;
  }

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

#include <bits/stdc++.h>

using namespace std;

int main() {
  int q, i, a, b, j;
  string str, m_str, t_str;
  string a_str, b_str;
  string c;

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

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  int q, i, a, b;
  string str, m_str, t_str;
  string a_str, b_str;

  cin >> str;
  cin >> q;
  for (i = 0; i < q; i++) {
    cin >> m_str;
    cin >> a >> b;
    if (m_str == "print")
      cout << str.substr(a, b - a + 1) << endl;
    else if (m_str == "reverse") {
      a_str = str.substr(0, a);
      b_str = str.substr(b + 1);
      t_str = str.substr(a, b - a + 1);
      reverse(t_str.begin(), t_str.end());
      str = a_str + t_str + b_str;
    } else if (m_str == "replace") {
      cin >> t_str;
      a_str = str.substr(0, a);
      b_str = str.substr(b - a + 2);
      str = a_str + t_str + b_str;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

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

  cin >> s;

  cin >> q;

  string order, str;

  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> str;
      s.replace(a, str.size(), str);
    } else if (order == "reverse") {
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (order == "print") {
      cin >> a >> b;
      for (int i = a; i <= b; i++) {
        printf("%c", s[i]);
      }
      printf("\\n");
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  cin >> s;

  cin >> q;

  string order, str;

  for (int i = 0; i < q; i++) {
    cin >> order;
    if (order == "replace") {
      cin >> a >> b >> str;
      s.replace(a, b, str);
    } else if (order == "reverse") {
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    } else if (order == "print") {
      cin >> a >> b;
      for (int i = a; i <= b; i++) {
        printf("%c", s[i]);
      }
      printf("\\n");
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int q, num1, num2;
  string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる
  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> str2 >> num1 >> num2;
    if (str2 == "replace") {
      cin >> str3;
      str = str.replace(num1, num2 - num1 + 1, str3);
    }

    else if (str2 == "reverse") {
      while (num1 <= num2) {
        char tmp;
        tmp = str[num1];
        str[num1] = str[num2];
        str[num2] = tmp;
        num1++;
        num2--;
      }
    }

    else if (str2 == "print") {
      cout << str.substr(num1, num2 - num1 + 1) << endl;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int q, num1, num2;
  string str, str2, str3; // str1=最初の文字列 str2=条件当てはめる
  cin >> str >> q;

  for (int i = 0; i < q; i++) {
    cin >> str2 >> num1 >> num2;
    if (str2 == "replace") {
      cin >> str3;
      str = str.replace(num1, num2, str3);
    }

    else if (str2 == "reverse") {
      while (num1 <= num2) {
        char tmp;
        tmp = str[num1];
        str[num1] = str[num2];
        str[num2] = tmp;
        num1++;
        num2--;
      }
    }

    else if (str2 == "print") {
      cout << str.substr(num1, num2 - num1 + 1) << endl;
    }
  }

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

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cctype>
#include <fstream>
#include <locale>
#include <math.h>
#include <numeric>
#include <regex>
#include <stdlib.h>

// #include <map>

using namespace std;

class cFunc {
public:
  string sfunc;
  int arg1;
  int arg2;
  string arg3;

  cFunc(string s) {
    istringstream iss;
    iss.str(s);
    iss >> sfunc >> arg1 >> arg2 >> arg3;
  }
};

int main() {
  string str;
  vector<string> vf;
  int q;

  cin >> str;
  cin >> q;
  cin.ignore();
  for (int i = 0; i < q; i++) {
    string temp;
    getline(cin, temp);
    vf.push_back(temp);
  }

  for (int i = 0; i < q; i++) {
    cFunc cf(vf.at(i));
    if (cf.sfunc == "replace") {
      str.replace(cf.arg1, cf.arg2 - cf.arg1 + 1, cf.arg3);
    } else if (cf.sfunc == "reverse") {
      reverse(str.begin() + cf.arg1, str.begin() + cf.arg2 + 1);
    } else if (cf.sfunc == "print") {
      string temp;
      temp = str.substr(cf.arg1, cf.arg2 - cf.arg1 + 1);
      cout << temp << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <cctype>
#include <fstream>
#include <locale>
#include <math.h>
#include <numeric>
#include <regex>
#include <stdlib.h>

// #include <map>

using namespace std;

class cFunc {
public:
  string sfunc;
  int arg1;
  int arg2;
  string arg3;

  cFunc(string s) {
    istringstream iss;
    iss.str(s);
    iss >> sfunc >> arg1 >> arg2 >> arg3;
  }
};

int main() {
  string str;
  vector<string> vf;
  int q;

  cin >> str;
  cin >> q;
  cin.ignore();
  for (int i = 0; i < q; i++) {
    string temp;
    getline(cin, temp);
    vf.push_back(temp);
  }

  for (int i = 0; i < q; i++) {
    cFunc cf(vf.at(i));
    if (cf.sfunc == "replace") {
      str.replace(cf.arg1, cf.arg2 - cf.arg1 + 1, cf.arg3);
    } else if (cf.sfunc == "reverse") {
      reverse(str.begin() + cf.arg1, str.end() - cf.arg2);
    } else if (cf.sfunc == "print") {
      str = str.substr(cf.arg1, cf.arg2 - cf.arg1 + 1);
      cout << str << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string reverse(string str) {
  string result = "";
  for (int i = str.size() - 1; 0 <= i; i--) {
    result += str[i];
  }
  return result;
}
int main() {
  string str;
  int q;
  string command;
  string PRINT = "print";
  string REVERSE = "reverse";
  string REPLACE = "replace";
  int a, b;
  string target;
  cin >> str;
  cin >> q;

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

    cin >> command;
    if (command == PRINT) {
      cin >> a >> b;
      // cout << PRINT  << "A : " << a << " B : " << b << endl;
      //    cout << str.substr(a, b+1) <<endl;
      cout << str.substr(a, b - a + 1) << endl;
    }
    if (command == REVERSE) {
      cin >> a >> b;
      // cout << REVERSE  << "A : " << a << " B : " << b << endl;
      str = str.substr(0, a) + reverse(str.substr(a, b - a + 1)) +
            str.substr(b + 1, str.size() - 1);
      // cout << str.substr(0,a) << reverse(str.substr(a,b-a+1)) <<
      // str.substr(b+1,str.size()-1) << endl;
    }
    if (command == REPLACE) {
      cin >> a >> b >> target;
      // cout << REPLACE << " A : " << a << " B : " << b << " Target : " <<
      // target;
      str = str.replace(a, b - a + 1, target);
      // cout << "REPLACED " << str <<  " " <<endl;
      // cout << REPLACE << " : " << str  << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string reverse(string str) {
  string result = "";
  for (int i = str.size() - 1; 0 <= i; i--) {
    result += str[i];
  }
  return result;
}
int main() {
  string str;
  int q;
  string command;
  string PRINT = "print";
  string REVERSE = "reverse";
  string REPLACE = "replace";
  int a, b;
  string target;
  cin >> str;
  cin >> q;

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

    cin >> command;
    if (command == PRINT) {
      cin >> a >> b;
      cout << str.substr(a, b + 1) << endl;
    }
    if (command == REVERSE) {
      cin >> a >> b;
      str = str.substr(0, a) + reverse(str.substr(a, b + 1)) +
            str.substr(b + 1, str.size());
    }
    if (command == REPLACE) {
      cin >> a >> b >> target;
      str = str.replace(a, b, target);
    }
  }

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

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

int main() {

  string str;
  int q;
  cin >> str;
  cin >> q;

  string cmd;
  int a, b;
  string str_insert;

  for (int i = 0; i < q; i++) {
    cin >> cmd >> a >> b;

    if (cmd == "replace") {
      cin >> str_insert;
      str.replace(a, b - a + 1, str_insert);
    } else if (cmd == "reverse") {
      for (int j = 0; j <= 1000; j++) {
        if (a + j >= b - j)
          break;
        char d = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = d;
      }
    } else if (cmd == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

int main() {

  string str;
  int q;
  cin >> str;
  cin >> q;

  string cmd;
  int a, b;
  string str_insert;

  for (int i = 0; i < q; i++) {
    cin >> cmd >> a >> b;

    if (cmd == "replace") {
      cin >> str_insert;
      str.replace(a, b, str_insert);
    } else if (cmd == "reverse") {
      for (int j = 0; j <= 100; j++) {
        if (a + j >= b - j)
          break;
        char d = str[a + j];
        str[a + j] = str[b - j];
        str[b - j] = d;
      }
    } else if (cmd == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str, meirei, p, x;
  int q, a, b;

  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> meirei >> a >> b;
    if (meirei == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (meirei == "reverse") {
      while (a <= b) {
        char temp = str[a];
        str[a] = str[b];
        str[b] = temp;
        a++;
        b--;
      }
    } else if (meirei == "replace") {
      cin >> p;
      for (int i = a; i <= b; i++) {
        str[i] = p[i - a];
      }
    }
  }

  return 0;
}

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


Fixed submission:

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

int main() {
  string str, meirei, p, x, c;
  int q, a, b;

  cin >> str >> q;
  for (int i = 0; i < q; i++) {
    cin >> meirei >> a >> b;
    if (meirei == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (meirei == "reverse") {
      while (a <= b) {
        char temp = str[a];
        str[a] = str[b];
        str[b] = temp;
        a++;
        b--;
      }

      str = c;
    } else if (meirei == "replace") {
      cin >> p;
      str = str.substr(a, b - a + 1) = p;
    }
  }
  cout << str << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string sub(int a, int b, string S) {
  string R;
  for (int i = a; i < b; i++) {
    R += S[i];
  }
  return R;
}
string Rev(int a, int b, string S) {
  string R;
  for (int i = a; i < b; i++) {
  }
}
int main(void) {
  // Your code here!
  int i, n, m, t = 0, h = 0;
  string T, H, A = "", B, C;
  cin >> H >> n;
  // cout<<H<<endl;
  for (i = 0; i < n; i++) {
    cin >> T;
    if (T == "print") {
      cin >> m >> t;

      cout << sub(m, t + 1, H) << endl;
    } else if (T == "reverse") {
      cin >> m >> t;
      C = sub(m, t + 1, H);

      reverse(C.begin(), C.end());
      // cout<<H<<endl;
      H.replace(m, C.size(), C);

      // cout<<H<<endl;
    } else if (T == "replace") {
      cin >> m >> t >> B;
      H.replace(m, B.size(), B);
      // cout<<H<<endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int i, n, m, t = 0, h = 0;
  string T, H, A = "", B, C;
  cin >> H >> n;
  for (i = 0; i < n; i++) {
    cin >> T;
    if (T == "print") {
      cin >> m >> t;
      H = H.substr(m, t + 1);
      cout << H << endl;
    } else if (T == "reverse") {
      cin >> m >> t;
      C = H.substr(m, t + 1);

      reverse(C.begin(), C.end());
      H = H.replace(m, t + 1, C);

    } else if (T == "replace") {
      cin >> m >> t >> B;
      H = H.replace(m, t, B);
    }
  }
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;
int main() {
  string main, str, sidestr;
  int n, i, j;
  cin >> main >> n;
  for (int p = 0; p < n; p++) {
    cin >> str;
    if (str == "replace") {
      cin >> i >> j >> sidestr;
      main.replace(i, j + 1 - i, sidestr);
    } else if (str == "reverse") {
      cin >> i >> j;
      string pickles = main.substr(i, j + 1 - i);
      reverse(pickles.begin(), pickles.end());
      main.replace(i, j + 1 - i, pickles);
    } else {
      cin >> i >> j;
      cout << main.substr(i, (j + 1 - i)) << endl;
    }
  }
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;
int main() {
  string main, str, sidestr;
  int n, i, j;
  cin >> main >> n;
  for (int p = 0; p < n; p++) {
    cin >> str;
    if (str == "replace") {
      cin >> i >> j >> sidestr;
      main.replace(i, j, sidestr);
    } else if (str == "reverse") {
      cin >> i >> j;
      string pickles = main.substr(i, j + 1 - i);
      reverse(pickles.begin(), pickles.end());
      main.replace(i, j + 1 - i, pickles);
    } else {
      cin >> i >> j;
      cout << main.substr(i, (j + 1)) << endl;
    }
  }
}