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

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

int main(void) {
  char s[101], p[101], copy[201];

  scanf("%s", s);
  scanf("%s", p);

  strcpy(copy, s);
  strcat(copy, s);
  if (strstr(copy, p) != NULL) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  int find;
  char s[202], p[101];

  scanf("%s", s);
  scanf("%s", p);

  strcat(s, s);
  if (strstr(s, p) != NULL) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }

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

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

int main(void) {

  string s, p;
  cin >> s >> p;
  s += s;

  for (int i = 0; i < s.size(); i++) {
    bool f = true;
    for (int j = 0; j < p.size(); j++) {
      if (i + j >= s.size()) {
        f = false;
        break;
      }
      if (s[i + j] != p[j]) {
        f = false;
        break;
      }
      // cerr << s[i+j] << " " << p[j] << endl;
    }
    if (f) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Error: 0
a a
a a
d d
v v
a a
n n
c c
e e


Fixed submission:

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

int main(void) {

  string s, p;
  cin >> s >> p;
  s += s;

  for (int i = 0; i < s.size(); i++) {
    bool f = true;
    for (int j = 0; j < p.size(); j++) {
      if (s[i + j] != p[j]) {
        f = false;
        break;
      }
      cerr << s[i + j] << " " << p[j] << endl;
    }
    if (f) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

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

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

int main() {
  char s[201] = {}, p[100] = {}, t[100] = {};
  cin >> s >> p;
  strcpy(t, s);
  strcat(s, t);
  if (strstr(s, p)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  char s[201] = {}, p[100] = {};
  cin >> s >> p;
  strcat(s, s);
  if (strstr(s, p)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

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

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
  char s[202], p[101], s2[101];
  cin >> s >> p;

  strcpy(s2, s);
  strcat(s, s2);

  if (strstr(s, p) != NULL) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(void) {
  char s[100], p[100], s2[100], s3[100];
  cin >> s >> p;

  strcpy(s2, s);
  strcat(s, s2);
  strcpy(s3, s);

  if (strstr(s3, p) != NULL) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}
Problem p02418 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  string s, p;
  cin >> s >> p;

  for (int i = 0; i < s.length(); i++) {
    if (s.find(p) != string::npos) {
      cout << "Yes" << endl;
      return 0;
    }
    s = s.substr(1) + s[0];
  }
  cout << "No" << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  string s, p;
  cin >> s >> p;

  string buf = s;
aiueo:
  for (int i = 0; i < s.length(); i++) {
    if (buf.find(p) != string::npos) {
      cout << "Yes" << endl;
      return 0;
    }
    buf = s.substr(i + 1) + s.substr(0, i);
  }
  cout << "No" << endl;
  goto aiueo;
}
Problem p02420 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

char tolower(char ch) {
  if ('A' <= 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 p02420 (C++) — buggy submission, verdict: 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, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
}

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


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 + 1, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
}
Problem p02420 (C++) — buggy submission, verdict: 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 = 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++;
  }
}

Error: 0

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, 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, verdict: 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 = 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++;
  }
}

Error: 0

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;
  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++;
  }
}
Problem p02420 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string deck, buffer1, buffer2, result;
  int m, h, decklen;

  while (1) {
    cin >> deck;
    if (deck == "-")
      break;
    decklen = deck.length();
    cin >> m;

    for (int i = 0; i < m; i++) {
      scanf("%d", &h);
      buffer1 = deck.substr(0, h);
      buffer2 = deck.substr(h);
      deck = buffer2 + buffer1;
    }
    cout << deck << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string deck, buffer1, buffer2, result;
  int h, decklen;

  while (1) {
    cin >> deck;
    if (deck == "-")
      break;
    decklen = deck.length();
    while (scanf("%d", &h) != EOF) {
      buffer1 = deck.substr(0, h);
      buffer2 = deck.substr(h + 1, decklen - h - 1);
      result = buffer1 + buffer2;
    }
    cout << result << endl;
  }
  return 0;
}
Problem p02420 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int m, n, i;
  string a, b, c;
  while (1) {
    cin >> a;
    if (a == "-")
      break;
    cin >> m;
    for (i = 1; i <= m; i++) {
      cin >> n;
      b = a.substr(0, n);
      c = a.erase(0, n);
      a = c + b;
    }
    cout << a << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int m, h;
  string left, right, a;
  cin >> m;
  while (1) {
    cin >> a;
    if (a == "-")
      break;
    for (int i = 0; i < m; i++) {
      cin >> h;
      left = a.substr(0, h);
      right = a.substr(h);
      a = right + left;
    }
    cout << a << endl;
  }
}
Problem p02420 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, ss;
  int n, m;
  while (true) {
    cin >> s;
    if (s == "-") {
      return 0;
    }
    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> m;
      s.insert(s.length(), s.substr(0, m));
      s.erase(0, m);
    }
    cout << s << endl;
  }
}

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


Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int main() {
  string s, ss;
  int n, m;
  while (true) {
    cin >> s;
    cin >> n;

    for (int i = 0; i < n; ++i) {
      cin >> m;
      ss = s.substr(0, m);
      s.insert(s.length(), s.substr(0, m));
      s.erase(m);
    }
    cout << s << endl;
  }
}
Problem p02420 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  string L, R, all, r, l;

  int m, h = 2, p, q;

  while (1) {

    cin >> all;

    cin >> m;

    if (all == "-")
      break;

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

      cin >> h;
      p = h;
      q = all.size();

      L = all.substr(0, h);
      R = all.substr(p, q - h + 1);
      l = L;
      r = R;
      all = r + l;
    }

    cout << all << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string L, R, all;

  int m, h, p;

  while (1) {

    cin >> all;

    if (all == "-")
      break;

    cin >> m;

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

      cin >> h;
      p = h + 1;

      std::string L = all.substr(0, h);
      std::string R = all.substr(p, all.size());
      std::string all = L + R;
    }

    std::cout << all << std::endl;
  }

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

#include <iostream>
#include <string>
using namespace std;
int main() {
  int h, m;
  string all, l, r;
  while (1) {
    cin >> all >> m;
    if (all == "-")
      break;
    for (int i = 0; i < m; i++) {
      cin >> h;
      l = all.substr(0, h);
      r = all.substr(h, -1);
      all = r + l;
    }
    cout << all << endl;
  }
  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 <iostream>
#include <string>
using namespace std;
int main() {
  string L, R, all;
  int m, h[99];
  while (1) {
    cin >> all;
    cin >> m;
    cin >> h[m];

    for (int i = 0; i < m; i++) {
      L = all.substr(0, h[m]);
      R = all.substr(h[m] + 1, all.size());
      all = R + L;
    }
    if (all == "-")
      break;
  }

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

#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");
  }
}

Error: 0

Fixed submission:

#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");
  }
}
Problem p02420 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
int main() {
  queue<char> Q;
  char a[202];
  int m, h, c;
  char x;
  while (1) {
    cin >> a;
    if (a[0] == '-')
      break;
    c = strlen(a);
    for (int i = 0; i < c; i++) {
      Q.push(a[i]);
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      for (int j = 0; j < h; j++) {
        x = Q.front();
        Q.pop();
        Q.push(x);
      }
    }
    while (!Q.empty()) {
      cout << Q.front();
      Q.pop();
    }
    cout << 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 <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  string s;
  string x;
  string y;
  while (1) {
    cin >> s;
    int len = s.length();
    if (s[0] == '-')
      break;
    int m, n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> m;
      x = s.substr(n, s.length() - 1);
      y = s.substr(0, n - 1);
      s = x + y;
    }
    cout << s << endl;
  }
}
Problem p02420 (C++) — buggy submission, verdict: 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;
}


Error: TLE

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 p02420 (C++) — buggy submission, verdict: Runtime Error

//
//  main.cpp
//  TP1_9-B
//
//  Created by Saicj on 2015/08/04.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

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

int main(int argc, const char *argv[]) {

  std::vector<string> results;

  string str;
  int count;
  string shuffle;

  while (true) {

    cin >> str;

    if (str == "-") {
      break;
    }

    cin >> count;

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

      cin >> shuffle;

      int shuffleNum = atoi(shuffle.c_str());

      string left = str.substr(0, shuffleNum);
      string right = str.substr(shuffleNum, str.size());

      str = right + left;
    }
    cout << str << endl;
  }

  return 0;
}

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


Fixed submission:

//
//  main.cpp
//  TP1_9-B
//
//  Created by Saicj on 2015/08/04.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

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

int main(int argc, const char *argv[]) {

  std::vector<string> results;

  string str;
  int count;
  string shuffle;

  while (str != "-") {

    cin >> str;
    cin >> count;

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

      cin >> shuffle;

      int shuffleNum = atoi(shuffle.c_str());

      string left = str.substr(0, shuffleNum);
      string right = str.substr(shuffleNum, str.size());

      str = right + left;
    }
    cout << str << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  char str[202];
  char temp[202];
  while (1) {
    for (int a = 0; a < 202; a++)
      str[a] = '0';
    int count, length = 0;
    cin >> str;
    if (str[0] == '-')
      break;
    for (int a = 0; str[a] != '0'; a++)
      length++;
    length--;
    // cout << "length "<<length<<endl;
    // for(int a = 0;a<length;a++)cout << str[a];
    cin >> count;
    for (; count > 0; count--) {
      int frame;
      cin >> frame;
      // cout << "frame " << frame<<endl;
      for (int a = 0; a < frame; a++)
        temp[a] = str[a];
      // cout << "temp ";
      // for(int a = 0;a<frame;a++)cout << temp[a];
      // cout << endl;
      for (int a = 0; a < length - frame; a++)
        str[a] = str[a + frame];
      for (int a = 0; a < frame; a++)
        str[length - frame + a] = temp[a];

      // for(int a = 0;a<length;a++)cout << str[a];
      // cout << endl;
    }
    for (int a = 0; a < length; a++)
      cout << str[a];
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  char str[201];
  char temp[201];
  while (1) {
    for (int a = 0; a < 201; a++)
      str[a] = '0';
    int count, length = 0;
    cin >> str;
    if (str[0] == '-')
      break;
    for (int a = 0; str[a] != '0'; a++)
      length++;
    length--;
    // cout << "length "<<length<<endl;
    // for(int a = 0;a<length;a++)cout << str[a];
    cin >> count;
    for (; count > 0; count--) {
      int frame;
      cin >> frame;
      // cout << "frame " << frame<<endl;
      for (int a = 0; a < frame; a++)
        temp[a] = str[a];
      // cout << "temp ";
      // for(int a = 0;a<frame;a++)cout << temp[a];
      // cout << endl;
      for (int a = 0; a < length - frame; a++)
        str[a] = str[a + frame];
      for (int a = 0; a < frame; a++)
        str[length - frame + a] = temp[a];

      // for(int a = 0;a<length;a++)cout << str[a];
      // cout << endl;
    }
    for (int a = 0; a < length; a++)
      cout << str[a];
    cout << endl;
  }
  return 0;
}
Problem p02420 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string n, t;
  int h;
  int cnt;
  while (cin >> t) {
    // cout << "DEBUG:t=" << t << endl;
    if (t[0] == '-') {
      cout << n << endl;
      break;
    }

    if (isdigit(t[0])) {
      // cnt = (int)t[0] - '0';
      cnt = atoi(t.c_str());
      // cout << "DEBUG: COUNT=" << cnt << endl;

      for (int i = 0; i < cnt; i++) {
        int h;
        cin >> t;
        h = atoi(t.c_str());
        // h = (int)t[0] - '0';

        string sl = n.substr(0, h);
        string sr = n.substr(h);
        n = sr + sl;
      }
      // cout << "DEBUG: n=" << n << endl;
    } else {
      // cout << "DEBUG*2" << endl;

      if (!n.empty())
        cout << n << endl;
      n = t;
      continue;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string n, t;
  int h;
  int cnt;
  while (cin >> t) {
    // cout << "t=" << t << endl;
    if (t[0] == '-') {
      cout << n << endl;
      break;
    }

    if (isdigit(t[0])) {
      // cout << "*1" << endl;
      cnt = (int)t[0] - '0';

      for (int i = 0; i < cnt; i++) {
        int h;
        cin >> t;
        h = (int)t[0] - '0';

        string sl = n.substr(0, h);
        string sr = n.substr(h);
        n = sr + sl;
      }
    } else {
      if (!n.empty())
        cout << n << endl;
      n = t;
      continue;
    }
  }

  return 0;
}