prithivMLmods/Coder-Stat huggingface dataset:
Problem p02418 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  string s, p;
  cin >> s >> p;
  s = s + s;
  a = s.size() * 2 - 1;
  b = p.size();
  for (int i = 0; i < a; i++) {
    for (int n = 1; n < a; n++) {
      if (p == s.substr(i, n)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  string s, p;
  cin >> s >> p;
  s = s + s;
  a = s.size() * 2 - 1;
  b = s.size();
  for (int i = 0; i < b; i++) {
    for (int n = 1; n < a; n++) {
      if (p == s.substr(i, n)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}
Problem p02419 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>

using namespace std;

int main() {
  string T, S;
  int count = 0, i;
  cin >> S;
  while (T != "END_OF_TEXT") {
    cin >> T;
    for (i = 0; i < T.size(); i++) {
      if (T[i] >= 'A' && T[i] <= 'Z')
        T[i] += 32;
    }
    if (T == S)
      count++;
  }
  cout << count << endl;
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  string T, S;
  int count = 0, i;
  cin >> S;
  while (cin >> T, T != "END_OF_TEXT") {
    for (i = 0; i < T.size(); i++) {
      if (T[i] >= 'A' && T[i] <= 'Z')
        T[i] += 32;
    }
    if (T == S)
      count++;
  }
  cout << count << endl;
}
Problem p02419 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
char tolower(char ch) {
  if ('A' <= ch && ch && ch <= 'Z') {
    return ch - 'A' + 'a';
  } else {
    return ch;
  }
}
int main() {
  int count = 0;
  string W;
  cin >> W;
  string str;
  while (1) {
    cin >> str;
    if (str == "END_PF_TEXT")
      break;
    for (int i = 0; i < (int)str.size(); i++) {
      str[i] = tolower(str[i]);
    }
    if (str == W) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char tolower(char ch) {
  if ('A' <= ch && ch && ch <= 'Z') {
    return ch - 'A' + 'a';
  } else {
    return ch;
  }
}
int main() {
  int count = 0;
  string W;
  cin >> W;
  string str;
  while (1) {
    cin >> str;
    if (str == "END_OF_TEXT")
      break;
    for (int i = 0; i < (int)str.size(); i++) {
      str[i] = tolower(str[i]);
    }
    if (str == W) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02419 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define llong long long
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;

vector<string> split(string str, char delim) {
  vector<string> res;
  size_t current = 0, found;
  while ((found = str.find_first_of(delim, current)) != string::npos) {
    string tmp = string(str, current, found - current);
    res.push_back(tmp);
    current = found + 1;
  }
  string tmp = string(str, current, found - current);
  tmp.replace(tmp.size() - 1, tmp.size(), "\0");
  res.push_back(string(str, current, str.size() - current));
  return res;
}

char *StrToUpper(char *s) {
  char *p;
  for (p = s; *p; p++) {
    *p = toupper(*p);
  }
  return s;
}

int main() {
  char cword[11];
  cin >> cword;

  int cnt = 0;

  while (1) {
    char cstr[1001];
    cin >> cstr;

    if (string(cstr).find("END_OF_TEXT") != string::npos)
      break;

    string word = StrToUpper(cword);
    vector<string> vec = split(StrToUpper(cstr), ' ');
    // transform(word.begin(), word.end(), word.begin(), toupper);
    // transform(str.begin(), str.end(), str.begin(), toupper);
    int num = 0;

    for (int i = 0; i < vec.size(); i++) {
      if (vec[i] == word)
        cnt++;
    }
  }

  printf("%d\n", cnt);

  while (1) {
  }
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define llong long long
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;

vector<string> split(string str, char delim) {
  vector<string> res;
  size_t current = 0, found;
  while ((found = str.find_first_of(delim, current)) != string::npos) {
    string tmp = string(str, current, found - current);
    res.push_back(tmp);
    current = found + 1;
  }
  string tmp = string(str, current, found - current);
  tmp.replace(tmp.size() - 1, tmp.size(), "\0");
  res.push_back(string(str, current, str.size() - current));
  return res;
}

char *StrToUpper(char *s) {
  char *p;
  for (p = s; *p; p++) {
    *p = toupper(*p);
  }
  return s;
}

int main() {
  char cword[11];
  cin >> cword;

  int cnt = 0;

  while (1) {
    char cstr[1001];
    cin >> cstr;

    if (string(cstr).find("END_OF_TEXT") != string::npos)
      break;

    string word = StrToUpper(cword);
    vector<string> vec = split(StrToUpper(cstr), ' ');
    // transform(word.begin(), word.end(), word.begin(), toupper);
    // transform(str.begin(), str.end(), str.begin(), toupper);
    int num = 0;

    for (int i = 0; i < vec.size(); i++) {
      if (vec[i] == word)
        cnt++;
    }
  }

  printf("%d\n", cnt);
}
Problem p02419 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <iostream>
using namespace std;

#include <cstdio>
#include <cstring>
#include <string>

string Upper(string s) {
  string t = s;
  for (int i = 0; s.size(); i++) {
    t[i] = toupper(s[i]);
  }
  return t;
}

int main() {
  string W, T;
  int count = 0;

  cin >> W;
  W = Upper(W);

  while (1) {
    cin >> T;

    if (T == "END_OF_TEXT")
      break;
    T = Upper(T);
    if (T == W)
      count++;
  }

  cout << count << "\n";

  return 0;
}

Fixed submission:
#include <cctype>
#include <iostream>
using namespace std;

#include <cstdio>
#include <cstring>
#include <string>

string Upper(string s) {
  string t = s;
  for (int i = 0; i < s.size(); i++) {
    t[i] = toupper(s[i]);
  }
  return t;
}

int main() {
  string W, T;
  int count = 0;

  cin >> W;
  W = Upper(W);

  while (1) {
    cin >> T;

    if (T == "END_OF_TEXT")
      break;
    T = Upper(T);
    if (T == W)
      count++;
  }

  cout << count << "\n";

  return 0;
}
Problem p02419 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int ans = 0;
  string w;
  cin >> w;
  for (int i = 0; i < w.size(); i++) {
    if (isupper(w[i])) {
      w[i] = tolower(w[i]);
    }
  }
  string t;
  while (true) {
    cin >> t;
    if (t == "END???OF???TEXT")
      break;

    for (int j = 0; j < t.size(); j++) {
      if (isupper(t[j])) {
        t[j] = tolower(t[j]);
      }
    }

    if (t == w) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int ans = 0;
  string w;
  cin >> w;
  for (int i = 0; i < w.size(); i++) {
    if (isupper(w[i])) {
      w[i] = tolower(w[i]);
    }
  }
  string t;
  while (true) {
    cin >> t;
    if (t == "END_OF_TEXT")
      break;

    for (int j = 0; j < t.size(); j++) {
      if (isupper(t[j])) {
        t[j] = tolower(t[j]);
      }
    }

    if (t == w) {
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02419 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int cnt = 0, match = 0;
  string w, t[150];
  cin >> w;
  string tt;
  int a = 0;
  while (cin >> tt, tt != "END_OF_TEXT") {
    t[a] = tt;
    a++;
  }
  for (int j = 0; j < a; j++) {
    for (int i = 0; i < t[j].size(); i++) {
      if (w.size() != t[j].size()) {
        break;
      }
      if (32 + w[match] == t[j][i] || w[match] == t[j][i] ||
          w[match] == t[j][i] + 32) {
        match++;
      } else {
        match = 0;
      }
      if (match == w.size()) {
        cnt++;
        match = 0;
      }
    }
    match = 0;
  }
  cout << cnt << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int cnt = 0, match = 0;
  string w, t[300];
  cin >> w;
  string tt;
  int a = 0;
  while (cin >> tt, tt != "END_OF_TEXT") {
    t[a] = tt;
    a++;
  }
  for (int j = 0; j < a; j++) {
    for (int i = 0; i < t[j].size(); i++) {
      if (w.size() != t[j].size()) {
        break;
      }
      if (32 + w[match] == t[j][i] || w[match] == t[j][i] ||
          w[match] == t[j][i] + 32) {
        match++;
      } else {
        match = 0;
      }
      if (match == w.size()) {
        cnt++;
        match = 0;
      }
    }
    match = 0;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02419 (C++)

Buggy submission (status: Runtime Error):
//
//  main.cpp
//  ITP1-9-A
//
//  Created by h3037153 on 2017/08/28.
//  Copyright ?? 2017??´ h3037153. All rights reserved.
//
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string W, T[100];
  int i = 0, counter = 0, ii = 0, len;
  char ch = {};
  cin >> W;
  while (cin >> T[i]) {
    if (T[i] == "END_OF_TEXT") {
      break;
    }
    len = T[i].length();
    for (ii = 0; ii < len; ii++) {
      if (isupper(T[i][ii])) {
        ch = tolower(T[i][ii]);
        T[i][ii] = ch;
      }
    }
    if (T[i] == W) {
      counter++;
    } else
      i++;
  }
  cout << counter << endl;
  return 0;
}

Fixed submission:
//
//  main.cpp
//  ITP1-9-A
//
//  Created by h3037153 on 2017/08/28.
//  Copyright ?? 2017??´ h3037153. All rights reserved.
//
#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string W, T[1000];
  int i = 0, counter = 0, ii = 0, len;
  char ch = {};
  cin >> W;
  while (cin >> T[i]) {
    if (T[i] == "END_OF_TEXT") {
      break;
    }
    len = T[i].length();
    for (ii = 0; ii < len; ii++) {
      if (isupper(T[i][ii])) {
        ch = tolower(T[i][ii]);
        T[i][ii] = ch;
      }
    }
    if (T[i] == W) {
      counter++;
    } else
      i++;
  }
  cout << counter << endl;
  return 0;
}
Problem p02419 (Python)

Buggy submission (status: Runtime Error):
import sys

s = sys.stdin.read().split()
print(s[1:].split().count(s[0]))


Fixed submission:
import sys

s = input().lower()
t = sys.stdin.read().lower().split()
print(t.count(s))
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

int main() {
  std::string str;
  int m, h;

  while (true) {
    std::cin >> str;
    if (str == "-")
      break;
    std::cin >> m;

    for (int i = 0; i < m; i++) {
      std::cin >> h;
      str = str.substr(h) + str.erase(h);
    }
    std::cout << str << std::endl;
  }
}


Fixed submission:
#include <iostream>

int main() {
  std::string str;
  int m, h;

  while (true) {
    std::cin >> str;
    if (str == "-")
      break;
    std::cin >> m;

    for (int i = 0; i < m; i++) {
      std::cin >> h;
      str = str.substr(h) + str.substr(0, h);
    }
    std::cout << str << std::endl;
  }
}
Problem p02420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main() {
  char cards[200];
  char newCards[200];
  int m, cardsLen;
  // int h[100];
  int h;

  while (true) {
    scanf("%s", cards);
    if (cards == "-")
      goto length;

    cardsLen = 0;
    while (cards[cardsLen] != '\0')
      cardsLen++;

    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      // scanf("%d",&h[i]);
      scanf("%d", &h);

      for (int j = 0; j < cardsLen; j++) {
        newCards[j] = cards[(j + h) % cardsLen];
      }

      for (int j = 0; j < cardsLen; j++) {
        cards[j] = newCards[j];
      }
    }

    printf("%s\n", cards);
  }

length:
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  char cards[200];
  char newCards[200];
  int m, cardsLen;
  // int h[100];
  int h;

  while (true) {
    scanf("%s", cards);
    if (cards[0] == '-')
      break;

    cardsLen = 0;
    while (cards[cardsLen] != '\0')
      cardsLen++;

    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      // scanf("%d",&h[i]);
      scanf("%d", &h);

      for (int j = 0; j < cardsLen; j++) {
        newCards[j] = cards[(j + h) % cardsLen];
      }

      for (int j = 0; j < cardsLen; j++) {
        cards[j] = newCards[j];
      }
    }

    printf("%s\n", cards);
  }

length:
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
#define rep(i, a) for (int i = 0; i < a; ++i)

int main(void) {
  char s[250], t[250];
  int m, i, j, n, a;
  while (1) {
    scanf("%s", s);
    n = strlen(s);
    if (n == 1 && s[0] == '-')
      break;
    scanf("%d", &m);
    rep(i, m) {
      scanf("%d", a);
      rep(j, a) t[j] = s[j];
      t[a] = 0;
      rep(j, (n - a)) s[j] = s[j + a];
      rep(j, a) s[j + n - a] = t[j];
    }
    printf("%s\n", s);
  }
  return 0;
}


Fixed submission:
#include <stdio.h>
#include <string.h>
#define rep(i, a) for (int i = 0; i < a; ++i)

int main(void) {
  char s[250], t[250];
  int m, i, j, n, a;
  while (1) {
    scanf("%s", s);
    n = strlen(s);
    if (n == 1 && s[0] == '-')
      break;
    scanf("%d", &m);
    rep(i, m) {
      scanf("%d", &a);
      rep(j, a) t[j] = s[j];
      t[a] = 0;
      rep(j, (n - a)) s[j] = s[j + a];
      rep(j, a) s[j + n - a] = t[j];
    }
    printf("%s\n", s);
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  int m, h;

  while (1) {

    cin >> str >> m;
    if (str == "-")
      break;
    for (int i = 0; i < m; i++) {
      cin >> h;
      str = str.substr(h + 1, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  int m, h;

  while (1) {

    cin >> str >> m;
    if (str == "-")
      break;
    for (int i = 0; i < m; i++) {
      cin >> h;
      str = str.substr(h, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>

using namespace std;

int main() {

  string data, data_copy;
  int m, h;

  for (;;) {
    cin >> data;
    if (data == "_")
      break;
    data_copy = data;
    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> h;

      for (int j = 0; j < data.length(); j++) {
        if ((j + 1 - h) <= 0) {
          data[data.length() - h + j] = data_copy[j];

        } else {
          data[j - h] = data_copy[j];
        }

      } // data?????¨????????????
      for (int j = 0; j < data.length(); j++) {
        data_copy[j] = data[j];
      }

    } //?????£??????????????°???????????????
    cout << data << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {

  string data, data_copy;
  int m, h;

  for (;;) {
    cin >> data;
    if (data == "-")
      break;
    data_copy = data;
    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> h;

      for (int j = 0; j < data.length(); j++) {
        if ((j + 1 - h) <= 0) {
          data[data.length() - h + j] = data_copy[j];

        } else {
          data[j - h] = data_copy[j];
        }

      } // data?????¨????????????
      for (int j = 0; j < data.length(); j++) {
        data_copy[j] = data[j];
      }

    } //?????£??????????????°???????????????
    cout << data << endl;
  }

  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string s[1000] = {""};
  int m[1000] = {0};
  int h[1000][1000] = {0};
  int i, j = 0;
  while (1) {
    cin >> s[i];
    if (s[i] == "-")
      break;
    cin >> m[i];
    for (int k = 0; k < m[i]; ++k) {
      cin >> h[i][k];
    }
    i++;
  }
  i = 0;
  while (1) {
    if (s[i] == "-")
      break;
    for (int k = 0; k < m[i]; ++k) {
      for (int l = 0; l < h[i][k]; ++l) {
        s[i] += s[i][0];
        s[i].erase(0, 1);
      }
    }
    cout << s[i] << endl;
    i++;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string s[1000] = {""};
  int m[1000] = {0};
  int h[1000][1000] = {0};
  int i = 0;
  int j = 0;
  while (1) {
    cin >> s[i];
    if (s[i] == "-")
      break;
    cin >> m[i];
    for (int k = 0; k < m[i]; ++k) {
      cin >> h[i][k];
    }
    i++;
  }
  i = 0;
  while (1) {
    if (s[i] == "-")
      break;
    for (int k = 0; k < m[i]; ++k) {
      for (int l = 0; l < h[i][k]; ++l) {
        s[i] += s[i][0];
        s[i].erase(0, 1);
      }
    }
    cout << s[i] << endl;
    i++;
  }
}
Problem p02420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  string s;
  while (cin >> s && s != "-") {
    int m, x = 0;
    while (m--) {
      int a;
      cin >> a;
      x += a;
    }
    REP(i, s.length()) { cout << s[(i + x) % s.length()]; }
    cout << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  string s;
  while (cin >> s && s != "-") {
    int m, x = 0;
    cin >> m;
    while (m--) {
      int a;
      cin >> a;
      x += a;
    }
    REP(i, s.length()) { cout << s[(i + x) % s.length()]; }
    cout << endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int m, now, temp, tot;
  char a[101], b[101];
  for (int i = 0; i < 101; i++)
    b[i] = a[i] = '\0';
  while (1) {
    scanf("%s", a);
    if (a[0] == '-')
      return 0;
    now = 0;
    while (a[now] != '\0')
      now++;
    scanf("%d", &m);
    tot = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d", &temp);
      tot += temp;
    }
    temp = tot % now;
    for (int j = 0; j < temp; j++)
      b[j] = a[j];
    for (int j = temp; j < now; j++) {
      a[j - temp] = a[j];
    }
    for (int j = 0; j < temp; j++) {
      a[now - temp + j] = b[j];
    }

    for (int i = 0; i < now; i++) {
      printf("%c", a[i]);
      b[i] = a[i] = '\0';
    }
    printf("\n");
  }
}

Fixed submission:
#include <stdio.h>
int main() {
  int m, now, temp, tot;
  char a[1001], b[1001];
  for (int i = 0; i < 1001; i++)
    b[i] = a[i] = '\0';
  while (1) {
    scanf("%s", a);
    if (a[0] == '-')
      return 0;
    now = 0;
    while (a[now] != '\0')
      now++;
    scanf("%d", &m);
    tot = 0;
    for (int i = 0; i < m; i++) {
      scanf("%d", &temp);
      tot += temp;
    }
    temp = tot % now;
    for (int j = 0; j < temp; j++)
      b[j] = a[j];
    for (int j = temp; j < now; j++) {
      a[j - temp] = a[j];
    }
    for (int j = 0; j < temp; j++) {
      a[now - temp + j] = b[j];
    }

    for (int i = 0; i < now; i++) {
      printf("%c", a[i]);
      b[i] = a[i] = '\0';
    }
    printf("\n");
  }
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  int m, h;
  while (1) {
    char tmp[400];
    string str;
    cin >> str;
    if (str == "~") {
      break;
    }
    for (int i = 0; i < str.size(); i++) {
      tmp[i] = str[i];
      tmp[str.size() + i] = str[i];
    }
    cin >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
      cin >> h;
      sum += h;
    }
    int count = 0;
    for (int i = sum % str.size();; i++) {
      cout << tmp[i];
      count++;
      if (count == str.size()) {
        break;
      }
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  int m, h;
  while (1) {
    char tmp[400];
    string str;
    cin >> str;
    if (str == "-") {
      break;
    }
    for (int i = 0; i < str.size(); i++) {
      tmp[i] = str[i];
      tmp[str.size() + i] = str[i];
    }
    cin >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
      cin >> h;
      sum += h;
    }
    int count = 0;
    for (int i = sum % str.size();; i++) {
      cout << tmp[i];
      count++;
      if (count == str.size()) {
        break;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  int m, n;
  std::string str, tes;
  while (true) {
    std::cin >> str >> m;
    if (m == '-')
      break;
    for (int a = 0; a < m; a++) {
      std::cin >> n;
      tes = str.substr(0, n);
      str.erase(str.begin(), str.begin() + n);
      str += tes;
    }
    std::cout << str << std::endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  int m, n;
  std::string str, tes;
  while (true) {
    std::cin >> str >> m;
    if (str == "-")
      break;
    for (int a = 0; a < m; a++) {
      std::cin >> n;
      tes = str.substr(0, n);
      str.erase(str.begin(), str.begin() + n);
      str += tes;
    }
    std::cout << str << std::endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  string ch, x;
  int kai, shu;
  while (1) {
    cin >> ch;
    x = ch;
    if (ch == "_")
      break;
    cin >> kai;
    for (int i = 0; i < kai; i++) {
      cin >> shu;
      for (int j = 0; j < shu; j++) {
        x[j] = ch[j];
      }
      // cout << ch << endl;
      for (int j = 0; j < ch.size() - shu; j++) {
        ch[j] = ch[j + shu];
      }
      for (int j = 0; j < shu; j++) {
        ch[(ch.size() - shu) + j] = x[j];
      }
      // cout << ch << endl;
    }
    cout << ch << endl;
  }

  return 0;
}

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

int main() {
  string ch, x;
  int kai, shu;
  while (1) {
    cin >> ch;
    x = ch;
    if (ch == "-")
      break;
    cin >> kai;
    for (int i = 0; i < kai; i++) {
      cin >> shu;
      for (int j = 0; j < shu; j++) {
        x[j] = ch[j];
      }
      // cout << ch << endl;
      for (int j = 0; j < ch.size() - shu; j++) {
        ch[j] = ch[j + shu];
      }
      for (int j = 0; j < shu; j++) {
        ch[(ch.size() - shu) + j] = x[j];
      }
      // cout << ch << endl;
    }
    cout << ch << endl;
  }

  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string card;
  string right;
  string left;
  int n;
  int m;

  while (cin >> card, card != "-") {
    cin >> m;
    for (int i = 0; i < n; i++) {
      cin >> m;
      right = card.substr(0, m);
      left = card.substr(m);
      card = left + right;
    }
    cout << card << endl;
  }
  return 0;
}

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

int main() {
  string card;
  string right;
  string left;
  int n;
  int m;

  while (cin >> card, card != "-") {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> m;
      right = card.substr(0, m);
      left = card.substr(m);
      card = left + right;
    }
    cout << card << endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <iostream>
#include <string>

using namespace std;

string shuffle(string str, int h) {
  string head = str.substr(0, h);
  string tail = str.substr(h, str.size() - h);
  return tail + head;
}

int main() {
  string cards;
  int m, h;

  while (1) {
    cin >> cards;
    if (cards == "_")
      break;

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      cards = shuffle(cards, h);
    }
    cout << cards << endl;
  }
  return 0;
}

Fixed submission:
#include <cctype>
#include <iostream>
#include <string>

using namespace std;

string shuffle(string str, int h) {
  string head = str.substr(0, h);
  string tail = str.substr(h, str.size() - h);
  return tail + head;
}

int main() {
  string cards;
  int m, h;

  while (1) {
    cin >> cards;
    if (cards == "-")
      break;

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      cards = shuffle(cards, h);
    }
    cout << cards << endl;
  }
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

string shuffle(string str, int h) {
  string head = str.substr(0, h);
  string tail = str.substr(h, str.size() - h);
  return tail + head;
}

int main() {
  string cards;
  int m, h;

  while (1) {
    cin >> cards;
    if (cards == "_")
      break;

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      cards = shuffle(cards, h);
    }
    cout << cards << endl;
  }

  return 0;
}

Fixed submission:
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

string shuffle(string str, int h) {
  string head = str.substr(0, h);
  string tail = str.substr(h, str.size() - h);
  return tail + head;
}

int main() {
  string cards;
  int m, h;

  while (1) {
    cin >> cards;
    if (cards == "-")
      break;

    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      cards = shuffle(cards, h);
    }
    cout << cards << endl;
  }

  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>

int main(void) {
  int i, j;
  int m[256];
  int s[256] = {0};
  char c[256][201];
  int d[256] = {0};
  int k = 0;
  while (1) {
    scanf("%s", c[k]);
    if (strcmp(c[k], "_") == 0)
      break;
    while (c[k][d[k]] != '\0') {
      d[k]++;
    };

    scanf("%d", &m[k]);
    for (i = 0; i < m[k]; i++) {
      scanf("%d", &j);
      s[k] = s[k] + j;
    };
    s[k] = s[k] % d[k];
    k++;
  }

  for (i = 0; i < k; i++) {
    for (j = 0; j < d[i]; j++) {
      c[i][j + d[i]] = c[i][j];
    };
    for (j = 0; j < d[i]; j++) {
      printf("%c", c[i][j + s[i]]);
    };
    printf("\n");
  };
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>

int main(void) {
  int i, j;
  int m[256];
  int s[256] = {0};
  char c[256][201];
  int d[256] = {0};
  int k = 0;
  while (1) {
    scanf("%s", c[k]);
    if (strcmp(c[k], "-") == 0)
      break;
    while (c[k][d[k]] != '\0') {
      d[k]++;
    };

    scanf("%d", &m[k]);
    for (i = 0; i < m[k]; i++) {
      scanf("%d", &j);
      s[k] = s[k] + j;
    };
    s[k] = s[k] % d[k];
    k++;
  }

  for (i = 0; i < k; i++) {
    for (j = 0; j < d[i]; j++) {
      c[i][j + d[i]] = c[i][j];
    };
    for (j = 0; j < d[i]; j++) {
      printf("%c", c[i][j + s[i]]);
    };
    printf("\n");
  };
  return 0;
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  int m, h, i;

  while (cin >> str, str != "-") {
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> h;
      str = str.substr(h + 1, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
}

Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  int m, h, i;

  while (cin >> str, str != "-") {
    cin >> m;
    for (i = 0; i < m; i++) {
      cin >> h;
      str = str.substr(h, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string s[1000] = {""};
  int m[1000] = {0};
  int h[1000][1000] = {0};
  int i;
  int j;
  while (1) {
    cin >> s[i];
    if (s[i] == "-")
      break;
    cin >> m[i];
    for (int k = 0; k < m[i]; ++k) {
      cin >> h[i][k];
    }
    i++;
  }
  i = 0;
  while (1) {
    if (s[i] == "-")
      break;
    for (int k = 0; k < m[i]; ++k) {
      for (int l = 0; l < h[i][k]; ++l) {
        s[i] += s[i][0];
        s[i].erase(0, 1);
      }
    }
    cout << s[i] << endl;
    i++;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vi vector<int>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string s[1000] = {""};
  int m[1000] = {0};
  int h[1000][1000] = {0};
  int i = 0;
  int j = 0;
  while (1) {
    cin >> s[i];
    if (s[i] == "-")
      break;
    cin >> m[i];
    for (int k = 0; k < m[i]; ++k) {
      cin >> h[i][k];
    }
    i++;
  }
  i = 0;
  while (1) {
    if (s[i] == "-")
      break;
    for (int k = 0; k < m[i]; ++k) {
      for (int l = 0; l < h[i][k]; ++l) {
        s[i] += s[i][0];
        s[i].erase(0, 1);
      }
    }
    cout << s[i] << endl;
    i++;
  }
}
Problem p02420 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

int main() {
  char cards[200];
  int c, s, i;
  char t;

  while (true) {
    i = 0;
    scanf("%c", &t);
    if (t == '-') {
      return 0;
    }
    while (t - 10) {
      cards[i] = t;
      i++;
      scanf("%c", &t);
    }

    for (int j = 0; j < i; j++) {
      cards[j + i] = cards[j];
    }

    scanf("%d", &c);
    int sum = 0;
    for (int j = 0; j < c; j++) {
      scanf("%d", &s);
      sum += s;
    }
    sum %= i;
    scanf("%c", &t);
    for (int j = 0; j < i; j++) {
      printf("%c", cards[j + sum]);
    }
    printf("\n");
  }
}

Fixed submission:
#include <cstdio>

int main() {
  char cards[400];
  int c, s, i;
  char t;

  while (true) {
    i = 0;
    scanf("%c", &t);
    if (t == '-') {
      return 0;
    }
    while (t - 10) {
      cards[i] = t;
      i++;
      scanf("%c", &t);
    }

    for (int j = 0; j < i; j++) {
      cards[j + i] = cards[j];
    }

    scanf("%d", &c);
    int sum = 0;
    for (int j = 0; j < c; j++) {
      scanf("%d", &s);
      sum += s;
    }
    sum %= i;
    scanf("%c", &t);
    for (int j = 0; j < i; j++) {
      printf("%c", cards[j + sum]);
    }
    printf("\n");
  }
}
Problem p02420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  string card, sub;
  int m, h;

  while (1) {
    cin >> card;

    if (card == "_")
      break;

    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> h;
      sub = card.substr(0, h);
      card.erase(0, h);
      card = card + sub;
    }

    cout << card << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  string card, sub;
  int m, h;

  while (1) {
    cin >> card;

    if (card == "-")
      break;

    cin >> m;

    for (int i = 0; i < m; i++) {
      cin >> h;
      sub = card.substr(0, h);
      card.erase(0, h);
      card = card + sub;
    }

    cout << card << endl;
  }

  return 0;
}
Problem p02421 (C++)

Buggy submission (status: 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;
  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;
}

Fixed submission:
#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;
}
Problem p02421 (C++)

Buggy submission (status: 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[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;
}

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[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;
}
Problem p02421 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02422 (C++)

Buggy submission (status: 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, 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;
}

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 - 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;
}
Problem p02422 (C++)

Buggy submission (status: 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;
      strInput = strInput.replace(i, j, strTemp);
    } else {
      cout << strInput.substr(i, j - i + 1) << endl;
    }
  }
  // system("pause");
  return 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;
      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;
}
Problem p02422 (C++)

Buggy submission (status: 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, 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;
}

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 - 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;
}
Problem p02422 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>

using namespace std;

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

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

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

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

Fixed submission:
#include <algorithm>
#include <stdio.h>

using namespace std;

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

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

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

int q;

int main() {
  int a, b;
  string str, q_str, m_str;
  cin >> str;
  cin >> q;
  REP(i, q) {
    cin >> q_str;
    cin >> a >> b;
    if (q_str == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (q_str == "replace") {
      cin >> q_str;
      m_str = str.erase(a, b);
      str = m_str.insert(a, q_str);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
    // cout << str << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

#define FOR(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)

int q;

int main() {
  int a, b;
  string str, q_str, m_str;
  cin >> str;
  cin >> q;
  REP(i, q) {
    cin >> q_str;
    cin >> a >> b;
    if (q_str == "print") {
      cout << str.substr(a, b - a + 1) << endl;
    } else if (q_str == "replace") {
      cin >> q_str;
      m_str = str.erase(a, b - a + 1);
      str = m_str.insert(a, q_str);
    } else {
      reverse(str.begin() + a, str.begin() + b + 1);
    }
    // cout << str << endl;
  }
  return 0;
}
Problem p02422 (C++)

Buggy submission (status: 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, p);
    }
  }
  for (int i = 0; i < cou; i++) {
    cout << ans[i] << endl;
  }
}

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 - a) + 1, p);
    }
  }
  for (int i = 0; i < cou; i++) {
    cout << ans[i] << endl;
  }
}
Problem p02422 (C++)

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

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