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

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

int main() {
  string a, left, right;
  int h, m;
  while (1) {
    cin >> a;
    if (a == "-")
      break;
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      left = a.substr(0, h);
      right = a.substr(h, a.size());
      a = right + left;
    }
    cout << a << endl;
  }

  return 0;
}

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


Fixed submission:

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

int main() {
  string a, left, right;
  int h;
  cin >> a;
  while (cin >> h) {
    if (h == '-')
      break;
    left = a.substr(0, h);
    right = a.substr(h + 1, a.size());
    a = right + left;
  }

  cout << a << endl;

  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int taro_score = 0, hana_score = 0;
  for (int i = 0; i < n; ++i) {
    string taro, hana;
    cin >> taro >> hana;
    if (taro > hana) {
      taro_score += 3;
    } else if (taro < hana) {
      hana_score += 3;
    } else {
      taro_score++;
      hana_score++;
    }
  }
  cout << taro_score << " " << hana_score << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  int taro_score = 0, hana_score = 0;
  while (1) {
    string taro, hana;
    cin >> taro >> hana;
    if (taro > hana) {
      taro_score += 3;
    } else if (taro < hana) {
      hana_score += 3;
    } else {
      taro_score++;
      hana_score++;
    }
  }
  cout << taro_score << " " << hana_score << "\\n";
  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int judge(string WordT, string WordH) {
  int j = 0;
  int Judge = 0;
  while (j < WordT.size() && j < WordH.size()) {
    if (WordT[j] != WordH[j]) {
      if (WordT[j] > WordH[j])
        Judge = 1;
      if (WordT[j] < WordH[j])
        Judge = -1;
      break;
    }
    j++;
  }
  if (Judge == 0 && WordT.size() > WordH.size())
    Judge = 1;
  if (Judge == 0 && WordT.size() < WordH.size())
    Judge = -1;
  return Judge;
}

int main() {
  //???????????????????????°n????????????
  int n;
  cin >> n;
  //??????????????????????????????????????????
  vector<string> T;
  vector<string> H;
  for (int i = 0; i < n; i++) {
    string WordT;
    string WordH;
    cin >> WordT;
    cin >> WordH;
    T.push_back(WordT);
    H.push_back(WordH);
  }
  //????¨???????????¨??????????
  int PointT = 0;
  int PointH = 0;
  for (int i = 0; i < n; i++) {
    int Judge = judge(T[i], H[i]);
    if (Judge == 1)
      PointT += 3;
    if (Judge == 0)
      PointT++, PointH++;
    if (Judge == -1)
      PointH += 3;
  }
  //????¨????????????¨?????????
  cout << PointT << " " << PointH << endl;
  //	system("pause");
  return 0;
}

Error: TLE

Fixed submission:

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

int judge(string WordT, string WordH) {
  int j = 0;
  int Judge = 0;
  while (j < WordT.size() && j < WordH.size()) {
    if (WordT[j] != WordH[j]) {
      if (WordT[j] > WordH[j])
        Judge = 1;
      if (WordT[j] < WordH[j])
        Judge = -1;
      break;
    }
  }
  if (Judge == 0 && WordT.size() > WordH.size())
    Judge = 1;
  if (Judge == 0 && WordT.size() < WordH.size())
    Judge = -1;
  return Judge;
}

int main() {
  //???????????????????????°n????????????
  int n;
  cin >> n;
  //??????????????????????????????????????????
  vector<string> T;
  vector<string> H;
  for (int i = 0; i < n; i++) {
    string WordT;
    string WordH;
    cin >> WordT;
    cin >> WordH;
    T.push_back(WordT);
    H.push_back(WordH);
  }
  //????¨???????????¨??????????
  int PointT = 0;
  int PointH = 0;
  for (int i = 0; i < n; i++) {
    int Judge = judge(T[i], H[i]);
    if (Judge == 1)
      PointT += 3;
    if (Judge == -1)
      PointH += 3;
    if (Judge == 0) {
      PointT++;
      PointH++;
    }
  }
  //????¨????????????¨?????????
  cout << PointT << " " << PointH << endl;
  //	system("pause");
  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  scanf("%d\\n", &n);
  char t[101], h[101];
  int i, taro = 0, hanako = 0;
  for (i = 0; i < n; i++) {

    scanf("%s %s\\n", t, h);
    if (strcmp(t, h) > 0) {
      taro += 3;
    } else if (strcmp(t, h) == 0) {
      taro++;
      hanako++;
    } else {
      hanako += 3;
    }
  }
  printf("%d %d\\n", taro, hanako);
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, i, tarop = 0, hanakop = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    char *Taro, *Hanako;
    scanf("%s %s", Taro, Hanako);
    int j;
    for (j = 0;; j++) {
      if (strcmp(Taro + j, Hanako + j) > 0) {
        tarop++;
        break;
      } else if (strcmp(Taro + j, Hanako + j) < 0) {
        hanakop++;
        break;
      } else {
        if (Taro[j] == 0 && Hanako[j] == 0)
          break;
      }
    }
  }
  printf("%d %d", tarop, hanakop);
  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int judge(string card1, string card2);
int main() {
  int n;
  int t_win = 0, h_win = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t_card, h_card;
    cin >> t_card >> h_card;
    switch (judge(t_card, h_card)) {
    case 1:
      t_win += 3;
      break;
    case -1:
      h_win += 3;
      break;
    case 0:
      t_win++;
      h_win++;
      break;
    }
  }
  cout << t_win << " " << h_win << endl;
  return 0;
}
int judge(string card1, string card2) {
  int result = 0;
  int index = 0;
  while (true) {
    if (card1.length() == index || card2.length() == index) {
      result =
          (card1.length() == index ? (card2.length() == index ? 0 : -1) : 1);
      break;
    } else if (card1.at(index) != card2.at(index)) {
      result = card1.at(index) > card2.at(index) ? 1 : -1;
      break;
    }
    index++;
  }
  return result;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int judge(string card1, string card2);
int main() {
  int n;
  int t_win = 0, h_win = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string t_card, h_card;
    cin >> t_card >> h_card;
    switch (judge(t_card, h_card)) {
    case 1:
      t_win += 3;
      break;
    case -1:
      h_win += 3;
      break;
    case 0:
      t_win++;
      h_win++;
      break;
    }
  }
  cout << t_win << " " << h_win << endl;
  return 0;
}
int judge(string card1, string card2) {
  int result = 0;
  int index = 0;
  while (true) {
    if (card1.length() == index && card2.length() == index) {
      result = 0;
      break;
    }
    if (card1.at(index) > card2.at(index)) {
      result = 1;
      break;
    } else if (card1.at(index) < card2.at(index)) {
      result = -1;
      break;
    }
    index++;
  }
  return result;
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int i, j, n, m, t = 0, h = 0;
  string T, H;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> T >> H;
    if (T == H) {
      t++;
      h++;
    } else if (T < H) {
      h += 3;
    } else if (T > H) {
      t += 3;
    }
  }
  cout << t << " " << h << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  // Your code here!
  int i = 0, j = 0, k, t = 0, h = 0;
  string a;
  string s, f = "";
  cin >> k;
  for (i = 0; i < k; i++) {
    cin >> s >> f;
    while (1) {
      if ((int)s.at(j) > (int)f.at(j)) {
        t += 3;
        break;
      } else if ((int)s.at(j) < (int)f.at(j)) {
        h += 3;
        break;
      } else if (s.size() == f.size() /*&&j==s.size()*/) {
        t++;
        h++;
        break;
      }
      j++;
    }
  }
  cout << t << " " << h << endl;
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int counter;
  int taroPoint = 0, hanakoPoint = 0;
  string taroCard, hanakoCard;

  cin >> counter;

  for (int i = 0; i < counter; i++) {
    cin >> taroCard >> hanakoCard;
    if (taroCard == hanakoCard) {
      taroPoint++;
      hanakoPoint++;
      continue;
    }
    int length;
    length = taroCard.length() > hanakoCard.length() ? hanakoCard.length()
                                                     : taroCard.length();

    for (int j = 0; j < length; j++) {
      char taro = taroCard.at(j);
      char hanako = hanakoCard.at(j);

      if (taro < hanako) {
        taroPoint += 3;
        break;
      } else if (hanako < taro) {
        hanakoPoint += 3;
        break;
      }
      if (j == length - 1) {
        if (taroCard.length() < hanakoCard.length()) {
          taroPoint += 3;
        } else {
          hanakoPoint += 3;
        }
      }
    }
    // cout<<taroPoint<<" "<<hanakoPoint<<endl;
  }
  cout << hanakoPoint << " " << taroPoint << endl;

  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int counter;
  int taroPoint = 0, hanakoPoint = 0;
  string taroCard, hanakoCard;

  cin >> counter;

  for (int i = 0; i < counter; i++) {
    cin >> taroCard >> hanakoCard;
    if (taroCard == hanakoCard) {
      taroPoint++;
      hanakoPoint++;
      continue;
    }
    for (int j = 0; j < taroCard.length(); j++) {
      char taro = taroCard.at(j);
      char hanako = hanakoCard.at(j);

      if (taro > hanako) {
        taroPoint += 3;
      } else {
        hanakoPoint += 3;
      }
    }
  }
  cout << taroPoint << " " << hanakoPoint << endl;

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

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

int ps, pt;

int sdiff(string sx, string tx) {
  if (sx == tx) {
    ps = 1;
    pt = 1;
  } else if (sx > tx) {
    ps = 3;
    pt = 0;
  } else {
    ps = 0;
    pt = 3;
  }
  return 0;
}

int main(void) {
  int n, k, is, it;
  string s[1001] = {}, t[1001] = {};

  cin >> n;

  is = 0;
  it = 0;
  for (k = 1; k <= n; k++) {
    cin >> s[k] >> t[k];
    sdiff(s[k], t[k]);
    is = is + ps;
    it = it + pt;
  }

  cout << is << " " << it << endl;

  return 0;
}

Error: 0

Fixed submission:

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

int ps, pt;

int sdiff(string sx, string tx) {
  if (sx == tx) {
    ps = 1;
    pt = 1;
  } else if (sx > tx) {
    ps = 3;
    pt = 0;
  } else {
    ps = 0;
    pt = 3;
  }
  return 0;
}

int main(void) {
  int n, k, is, it;
  string s[101] = {}, t[101] = {};

  cin >> n;

  is = 0;
  it = 0;
  for (k = 1; k <= n; k++) {
    cin >> s[k] >> t[k];
    sdiff(s[k], t[k]);
    is = is + ps;
    it = it + pt;
  }

  cout << is << " " << it << endl;

  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a = 0, b = 0, n;
  string A, B;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A >> B;
    if (A == B) {
      a++;
      b++;
    } else if (A > B)
      a += 3;
    else
      b += 3;
  }
  cout << a << " " << b << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int taro, hanako, n;
  string animalt, animalh;
  cin >> n;
  for (int i = 0; i = n; i++) {
    cin >> animalt >> animalh;
    if (animalt[0] > animalh[0])
      taro += 3;
    else if (animalh[0] < animalh[0])
      hanako += 3;
    else if (animalh[0] = animalt[0]) {
      taro++;
      hanako++;
    }
  }
  cout << taro << " " << hanako << endl;
}
Problem p02421 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

int main() {
  int m;
  int ap = 0;
  int bp = 0;
  std::string a, b;
  std::cin >> m;
  for (int n = 0; n < m; n++) {
    std::cin >> a >> b;
    if (a > b)
      ap += 3;
    if (a < b)
      bp += 3;
    if (a == b) {
      ap += 1;
      bp += 1;
    }
  }
  std::cout << ap << " " << bp << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

int main() {
  int m;
  int ap = 0;
  int bp = 0;
  std::string a, b;
  while (true) {
    std::cin >> m;
    for (int n = 0; n < m; n++) {
      std::cin >> a >> b;
      if (a > b)
        ap += 3;
      if (a < b)
        bp += 3;
      if (a == b) {
        ap += 1;
        bp += 1;
      }
    }
    std::cout << ap << " " << bp << std::endl;
  }
  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, ts = 0, hs = 0;
  char t[100], h[100];
  cin >> n;
  while (n--) {
    cin >> t >> h;
    if (strcmp(t, h) > 0)
      ts += 3;
    else if (strcmp(t, h) < 0)
      hs += 3;
    else {
      ts += 1;
      hs += 1;
    }
  }
  cout << ts << ' ' << hs << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n, ts = 0, hs = 0;
  char *t, *h;
  cin >> n;
  while (n--) {
    cin >> t >> h;
    if (strcmp(t, h) > 0)
      ts += 3;
    else if (strcmp(t, h) < 0)
      hs += 3;
    else {
      ts += 1;
      hs += 1;
    }
  }
  cout << ts << ' ' << hs << endl;
  return 0;
}
Problem p02421 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  int n;
  cin >> n;
  int sum_t = 0, sum_h = 0;
  rep(i, n) {
    string taro, hana;
    cin >> taro >> hana;
    if (taro < hana) {
      sum_h += 3;
    } else if (taro > hana) {
      sum_t += 3;
    } else {
      sum_t += 1;
      sum_h += 1;
    }
  }
  cout << sum_t << ' ' << sum_h << endl;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  int n;
  while (cin >> n, n) {
    int sum_t = 0, sum_h = 0;
    rep(i, n) {
      string taro, hana;
      cin >> taro >> hana;
      if (taro < hana) {
        sum_h += 3;
      } else if (taro > hana) {
        sum_t += 3;
      } else {
        sum_t += 1;
        sum_h += 1;
      }
    }
    cout << sum_t << ' ' << sum_h << endl;
  }
}
Problem p02421 (C++) — buggy submission, verdict: Runtime Error

// memo : A is smaller than Z
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  vector<string> Taro, Hanako;
  string s1, s2;
  int i, j, n, Taro_Score = 0, Hanako_Score = 0, end_checker;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s1 >> s2;
    Taro.push_back(s1);
    Hanako.push_back(s2);
  }

  for (i = 0; i < Taro.size(); i++) {
    end_checker = 0;
    for (j = 0; j < Taro[i].length(); j++) {
      // T:cat,H:dog -> Taro wins
      if (Taro[i][j] > Hanako[i][j]) {
        Taro_Score += 3;
        end_checker = 1;
        break;
      }
      // T:dog,H:cat -> Hanako wins
      else if (Taro[i][j] < Hanako[i][j]) {
        Hanako_Score += 3;
        end_checker = 1;
        break;
      }
    }
    if (end_checker == 1) {
      continue;
    }

    if (Taro[i].length() > Hanako[i].length()) {
      Taro_Score += 3;
      end_checker = 1;
    } else if (Taro[i].length() < Hanako[i].length()) {
      Hanako_Score += 3;
      end_checker = 1;
    } else {
      Taro_Score++;
      Hanako_Score++;
      end_checker = 1;
    }
  }
  cout << Taro_Score << " " << Hanako_Score << endl;
  return 0;
}

Error: 0

Fixed submission:

// memo : A is smaller than Z
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  vector<string> Taro, Hanako;
  string s1, s2;
  int i, j, n, Taro_Score = 0, Hanako_Score = 0;
  int end_checker;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s1 >> s2;
    Taro.push_back(s1);
    Hanako.push_back(s2);
  }
  for (i = 0; i < Taro.size(); i++) {
    end_checker = 0;
    for (j = 0; j < Taro[i].length(); j++) {
      // T:cat,H:dog -> Taro wins
      if (Taro[i].at(j) > Hanako[i].at(j)) {
        Taro_Score += 3;
        end_checker = 1;
        break;
      }
      // T:dog,H:cat -> Hanako wins
      else if (Taro[i].at(j) < Hanako[i].at(j)) {
        Hanako_Score += 3;
        end_checker = 1;
        break;
      }
    }

    if (end_checker == 1) {
      continue;
    }

    if (Taro[i].length() > Hanako[i].length()) {
      Taro_Score += 3;
      end_checker = 1;
    } else if (Taro[i].length() < Hanako[i].length()) {
      Hanako_Score += 3;
      end_checker = 1;
    } else {
      Taro_Score++;
      Hanako_Score++;
      end_checker = 1;
    }
  }
  cout << Taro_Score << " " << Hanako_Score << endl;
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  string s;
  int q;

  cin >> s;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    string od, p;
    int a, b;

    cin >> od >> a >> b;
    if (od == "replace") {
      cin >> p;
      s = s.replace(a, b - a + 1, p);
    } else if (od == "print") {
      cout << s.substr(a, b - a + 1) << endl;
    } else if (od == "reverse") {
      string tmp = s.substr(a, b - a + 1);
      reverse(tmp.begin(), tmp.end());
      // cout <<"tmp=" << tmp <<endl;
      s = s.replace(a, b - a + 1, tmp);
    }

    // cout << s << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  string s;
  int q;

  cin >> s;
  cin >> q;

  for (int i = 0; i < q; ++i) {
    string od, p;
    int a, b;

    cin >> od >> a >> b;
    if (od == "replace") {
      cin >> p;
      s = s.replace(a, b, p);
    } else if (od == "print") {
      cout << s.substr(a, b - a + 1) << endl;
    } else if (od == "reverse") {
      string tmp = s.substr(a, b - a + 1);
      reverse(tmp.begin(), tmp.end());
      s = s.replace(a, b - a + 1, tmp);
    }

    // cout << s << endl;
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>

int main() {
  char str[1001], buff[1001], command[100];
  int q, a, b;

  scanf("%s", str);
  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s", command);
    if (strcmp(command, "print") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);
      for (int j = 0; j <= b - a; j++) {
        buff[j] = str[a + j];
      }
      buff[b - a + 1] = '\\0';
      printf("%s\\n", buff);
    } else if (strcmp(command, "reverse") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);
      strcpy(buff, str);
      for (int j = 0; j <= b - a; j++) {
        str[a + j] = buff[b - j];
      }
    } else if (strcmp(command, "replace") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);

      char p[b - a + 1];
      scanf("%s", p);

      for (int j = 0; j <= b - a; j++) {
        str[a + j] = p[j];
      }
    } else {
      printf("ERROR\\n");
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <vector>

int main() {
  char str[1001], buff[1001], command[100];
  int q, a, b;

  scanf("%s", str);
  scanf("%d", &q);

  for (int i = 0; i < q; i++) {
    scanf("%s", command);
    if (strcmp(command, "print") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);
      for (int j = 0; j <= b - a; j++) {
        buff[j] = str[a + j];
      }
      buff[b - a + 1] = '\\0';
      printf("%s\\n", buff);
    } else if (strcmp(command, "reverse") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);
      strcpy(buff, str);
      for (int j = 0; j <= b - a; j++) {
        str[a + j] = buff[b - j];
      }
    } else if (strcmp(command, "replace") == 0) {
      scanf("%d", &a);
      scanf("%d", &b);

      std::vector<char> p(b - a + 1);
      scanf("%s", p.data());

      for (int j = 0; j <= b - a; j++) {
        str[a + j] = p[j];
      }
    } else {
      printf("ERROR\\n");
      break;
    }
  }
  return 0;
}
Problem p02422 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  string str, str1, str2, str3;
  int q;
  int a, b;

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


Error: TLE

Fixed submission:

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

int main() {

  string str, str1, str2, str3;
  int q;
  int a, b;

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

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

int main() {
  string strInput, strTemp;
  int nCount;
  int i, j;
  cin >> strInput;
  cin >> nCount;
  while (nCount--) {
    cin >> strTemp >> i >> j;
    if ("reverse" == strTemp) {
      reverse(strInput.begin() + i, strInput.begin() + j + 1); // j+1
    } else if ("replace" == strTemp) {
      cin >> strTemp;
      for (int ii = 0; ii < j - i + 1; ii++) {
        strInput[i + ii] = strTemp[ii];
      }
    } else {
      cout << strInput.substr(i, j - i + 1) << endl;
    }
  }
  // system("pause");
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  string strInput, strTemp;
  int nCount;
  int i, j;
  cin >> strInput;
  cin >> nCount;
  while (nCount--) {
    cin >> strTemp >> i >> j;
    if ("reverse" == strTemp) {
      reverse(strInput.begin() + i, strInput.begin() + j + 1); // j+1
    } else if ("replace" == strTemp) {
      cin >> strTemp;
      strInput = strInput.replace(i, j, strTemp);
    } else {
      cout << strInput.substr(i, j - i + 1) << endl;
    }
  }
  // system("pause");
  return 0;
}