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

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int a[1000000];

int main() {
  int n, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> g;
  int h = 1;
  g.push_back(h);
  while (h * 3 + 1 < n) {
    h = h * 3 + 1;
    g.push_back(h);
  }
  for (int k = g.size() - 1; k >= 0; k--) {
    for (int i = g[k]; i < n; i++) {
      int v = a[i], j = i - g[k];
      while (j >= 0 && a[j] > v) {
        a[j + g[k]] = a[j];
        j -= g[k];
        cnt++;
      }
      a[j + g[k]] = v;
    }
  }
  cout << g.size() << endl;
  for (int i = 0; i < g.size(); i++) {
    if (i != 0)
      cout << " ";
    cout << g[g.size() - i - 1];
  }
  cout << endl << cnt << endl;
  for (int i = 0; i < n; i++)
    cout << a[i] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, a[100], cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> g;
  int h = 1;
  g.push_back(h);
  while (h * 3 + 1 < n) {
    h = h * 3 + 1;
    g.push_back(h);
  }
  for (int k = g.size() - 1; k >= 0; k--) {
    for (int i = g[k]; i < n; i++) {
      int v = a[i], j = i - g[k];
      while (j >= 0 && a[j] > v) {
        a[j + g[k]] = a[j];
        j -= g[k];
        cnt++;
      }
      a[j + g[k]] = v;
    }
  }
  cout << g.size() << endl;
  for (int i = 0; i < g.size(); i++) {
    if (i != 0)
      cout << " ";
    cout << g[g.size() - i - 1];
  }
  cout << endl << cnt << endl;
  for (int i = 0; i < n; i++)
    cout << a[i] << endl;
  return 0;
}
Problem p02262 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long n = 0, g = 0, v = 0, cnt = 0, m = 0;

  cin >> n;

  vector<long> a(n);

  for (long i = 0; i < n; i++)
    cin >> a[i];

  cnt = 0;
  if (n < 3)
    m = 1;
  else
    m = (int)(log(n) / log(3));

  vector<long> G(m);

  for (long k = 0; k < m; k++) {
    G[k] = ((long)pow(3, m - k) - 1) / 2;
    g = G[k];

    for (long i = g; i < n; i++) {

      long j = 0;

      v = a[i];
      j = i - g;

      while (j >= 0 && a[j] > v) {
        a[j + g] = a[j];
        j = j - g;
        cnt++;
      }

      a[j + g] = v;
    }
  }

  cout << m << endl;

  for (long i = 0; i < m - 1; i++)
    cout << G[i] << " ";
  cout << G[m - 1] << endl;

  cout << cnt << endl;

  for (long i = 0; i < n; i++)
    cout << a[i] << endl;

  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  long n = 0, g = 0, v = 0, cnt = 0, m = 0;

  cin >> n;

  vector<long> a(n);

  for (long i = 0; i < n; i++)
    cin >> a[i];

  cnt = 0;
  if (n == 1)
    m = 1;
  else
    m = (int)(log(n) / log(3));

  vector<long> G(m);

  for (long k = 0; k < m; k++) {
    G[k] = ((long)pow(3, m - k) - 1) / 2;
    g = G[k];

    for (long i = g; i < n; i++) {

      long j = 0;

      v = a[i];
      j = i - g;

      while (j >= 0 && a[j] > v) {
        a[j + g] = a[j];
        j = j - g;
        cnt++;
      }

      a[j + g] = v;
    }
  }

  cout << m << endl;

  for (long i = 0; i < m - 1; i++)
    cout << G[i] << " ";
  cout << G[m - 1] << endl;

  cout << cnt << endl;

  for (long i = 0; i < n; i++)
    cout << a[i] << endl;

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

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

using namespace std;

#define BUF_SIZE 1024

int count = 0;

void insertionSort(int array[], int n, int g) {
  int v, j;
  for (int i = g; i < n; i++) {
    v = array[i];
    j = i - g;
    while (j >= 0 && array[j] > v) {
      array[j + g] = array[j]; //??°??????????????§???????????????
      j = j - g;
      count++;
    }
    array[j + g] = v;
  }
}

void shellSort(int array[], int n) {
  int m = 0;
  int s = 1;

  while ((n / s) > 0) {
    s *= 2;
    m++; // 2^(mult-1)?????§?????????????????¨???????¨?
  }

  int G[20];

  for (int k = 0, t = 1; k < m; k++) {
    G[k] = n / t;
    t *= 2;
  }

  for (int i = 0; i < m; i++) {
    insertionSort(array, n, G[i]);
  }

  printf("%d\\n", m);
  for (int i = 0; i < m; i++) {
    if (i != m - 1) {
      printf("%d ", G[i]);
    } else {
      printf("%d\\n", G[i]);
    }
  }
  printf("%d\\n", count);
  for (int i = 0; i < n; i++) {
    printf("%d\\n", array[i]);
  }
}

int main(int argc, char *argv[]) {
  char buf[BUF_SIZE];
  int n = atoi(fgets(buf, BUF_SIZE, stdin));
  int array[1000000];

  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }

  shellSort(array, n);
}

Error: WA

Fixed submission:

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

using namespace std;

#define BUF_SIZE 1024

int count = 0;

void insertionSort(int array[], int n, int g) {
  int v, j;
  for (int i = g; i < n; i++) {
    v = array[i];
    j = i - g;
    while (j >= 0 && array[j] > v) {
      array[j + g] = array[j]; //??°??????????????§???????????????
      j = j - g;
      count++;
    }
    array[j + g] = v;
  }
}

void shellSort(int array[], int n) {
  int m = 0;
  int s = 1;

  while ((n / s) > 0) {
    s *= 2;
    m++; // 2^(mult-1)?????§?????????????????¨???????¨?
  }

  int G[20];

  for (int k = 0, t = 1; k < m; k++) {
    G[k] = n / t;
    t *= 2;
  }

  for (int i = 0; i < m; i++) {
    insertionSort(array, n, G[i]);
  }

  printf("%d\\n", m);
  for (int i = 0; i < m; i++) {
    if (i != m - 1) {
      printf("%d ", G[i]);
    } else {
      printf("%d\\n", G[i]);
    }
  }
  printf("%d\\n", count);
  for (int i = 0; i < n; i++) {
    printf("%d\\n", array[i]);
  }
}

int main(int argc, char *argv[]) {
  char buf[BUF_SIZE];
  int n = atoi(fgets(buf, BUF_SIZE, stdin));
  int array[1000];

  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }

  shellSort(array, n);
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  stack<int> st;
  vector<string> vec;
  string s;

  while (cin >> s) {
    vec.push_back(s);
  }

  for (int i = 0; i < (int)vec.size(); i++) {

    if (vec[i] == "+") {
      int a = st.top();
      st.pop();
      int b = st.top();
      st.pop();
      int c = a + b;
      st.push(c);
    }

    else if (vec[i] == "-") {
      int a = st.top();
      st.pop();
      int b = st.top();
      st.pop();
      int c = b - a;
      st.push(c);
    }

    else if (vec[i] == "*") {
      int a = st.top();
      st.pop();
      int b = st.top();
      st.pop();
      int c = a * b;
      st.push(c);
    }

    else {
      int num = stoi(vec[i]);
      st.push(num);
    }
  }

  int ans = st.top();

  cout << ans << endl;

  return 0;
}


Error: -11

Fixed submission:

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

int main() {

  int n, q;
  cin >> n >> q;

  vector<stack<int>> s(n);

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

    int a, t, x;
    cin >> a;
    if (a == 0) {
      cin >> t >> x;

      s[t].push(x);
    }

    if (a == 1) {
      cin >> t;
      if (!s[t].empty()) {
        cout << s[t].top() << endl;
      }
    }

    if (a == 2) {
      cin >> t;
      if (!s[t].empty())
        s[t].pop();
    }
  }

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


#include <iostream>
#include <stack>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
  string word;
  stack<int> S;
  int n, n1, n2, p;
  while (cin >> word) {
    if (word == "+") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n1 + n2;
      S.push(n);
    } else if (word == "-") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n2 - n1;
      S.push(n);
    } else if (word == "*") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n1 * n2;
      S.push(n);
    } else {
      p = atoi(word.c_str());
      S.push(p);
    }
  }
  cout << S.top() << endl;
  return 0;
}

Error: 3

Fixed submission:


#include <iostream>
#include <stack>
#include <stdlib.h>
#include <string>
using namespace std;
int main() {
  string word;
  stack<int> S;
  int n, n1, n2, p;
  while (cin >> word) {
    if (word == "+") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n1 + n2;
      S.push(n);
    } else if (word == "-") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n2 - n1;
      S.push(n);
    } else if (word == "*") {
      n1 = S.top();
      S.pop();
      n2 = S.top();
      S.pop();
      n = n1 * n2;
      S.push(n);
    } else {
      p = atoi(word.c_str());
      S.push(p);
    }
  }
  cout << S.top() << endl;
  return S.top();
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// using namespace std;
#define MAX 1000
int top;
int S[MAX];
void initialize() { top = 0; }
bool isEmpty() { return top == 0; }
bool isFull() { return top >= MAX - 1; }
void push(int x) {
  // if (isFull()){
  //     cout << "Error" <<endl;
  //     exit(-1);
  // }
  top++;
  S[top] = x;
}
int pop() {
  // if (isEmpty()){
  //     cout << "Error" <<endl;
  //     exit(-1);
  // }

  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  initialize();
  char s[MAX];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define MAX 100
int top;
int S[MAX];
void initialize() { top = 0; }
bool isEmpty() { return top == 0; }
bool isFull() { return top >= MAX - 1; }
void push(int x) {
  // if (isFull()){
  //     cout << "Error" <<endl;
  //     exit(-1);
  // }
  top++;
  S[top] = x;
}
int pop() {
  // if (isEmpty()){
  //     cout << "Error" <<endl;
  //     exit(-1);
  // }

  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  initialize();
  char s[MAX];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }

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

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

#include <cstdlib>
#include <iostream>

using namespace std;

int top, S[101];

void push(int x) { S[++top] = x; }

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  top = 0;
  string s;
  while (cin >> s) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s.c_str()));
    }
  }

  cout << pop() << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <cstdlib>
#include <iostream>

using namespace std;

int top, S[100];

void push(int x) { S[++top] = x; }

int pop() {
  top--;
  return S[top + 1];
}

int main() {
  int a, b;
  top = 0;
  string s;
  while (cin >> s) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s.c_str()));
    }
  }

  cout << pop() << endl;

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

#include <cstdlib>
#include <iostream>
#include <stack>

using namespace std;

stack<int> s;
char ch[11];

int main() {
  while (cin >> ch) {
    if (ch[0] != '+' && ch[0] != '-' && ch[0] != '*')
      s.push(atoi(ch));
    else if (ch[0] == '+') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(a + b);
    } else if (ch[0] == '-') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(b - a);
    } else if (ch[0] == '*') {
      int a = s.top();
      s.pop();
      int b = s.top();
      s.pop();
      s.push(a * b);
    }
  }
  cout << s.top() << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <cstdlib>
#include <iostream>
#include <stack>
using namespace std;

int main() {
  stack<int> S;
  int a, b, x;
  string s;

  while (cin >> s) {
    cout << S.top() << endl;

    if (s[0] == '+') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a + b);
    } else if (s[0] == '-') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a - b);
    } else if (s[0] == '*') {
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a * b);
    } else {
      S.push(atoi(s.c_str()));
    }
  }

  cout << S.top() << endl;

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

#include <stdio.h>
#include <stdlib.h>

int top;
int stack[100];

int pop() { return stack[top--]; }

void push(int num) { stack[++top] = num; }

int main() {
  int a, b;
  char s[7];
  top = -1;

  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else if (s[0] == '-') {
      a = pop();
      b = pop();
      push(b - a);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\\n", pop());
  return 0;
}


Error: -11

Fixed submission:

#include <stdio.h>
#include <stdlib.h>

int top;
int stack[1000];

int pop() { return stack[top--]; }

void push(int num) { stack[++top] = num; }

int main() {
  int a, b;
  char s[7];
  top = -1;

  while (scanf("%s", s) != 'n') {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else if (s[0] == '-') {
      a = pop();
      b = pop();
      push(b - a);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\\n", pop());
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str, buf;
  stack<long long int> memory;
  long long int a, b;
  getline(cin, str);
  stringstream ss(str);
  while (ss >> buf) {
    a = atoi(buf.c_str());
    if (buf == "+") {
      a = memory.top();
      memory.pop();
      b = memory.top();
      memory.pop();
      memory.push(a + b);
    } else if (buf == "-") {
      a = memory.top();
      memory.pop();
      b = memory.top();
      memory.pop();
      memory.push(b - a);
    } else if (buf == "*") {
      a = memory.top();
      memory.pop();
      b = memory.top();
      memory.pop();
      memory.push(a * b);
    } else if (buf == "/") {
      a = memory.top();
      memory.pop();
      b = memory.top();
      memory.pop();
      memory.push(b / a);
    } else
      memory.push(a);
  }
  cout << memory.top() << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
using namespace std;

int main() {
  string str, buf;
  stack<long long int> memory;
  long long int a, b;
  getline(cin, str);
  stringstream ss(str);
  while (ss >> buf) {
    a = atoi(buf.c_str());
    if (!a) {
      a = memory.top();
      memory.pop();
      b = memory.top();
      memory.pop();
      if (buf == "+") {
        memory.push(a + b);
      } else if (buf == "-") {
        memory.push(b - a);
      } else if (buf == "*") {
        memory.push(a * b);
      } else {
        memory.push(b / a);
      }
    } else {
      memory.push(a);
    }
  }
  cout << memory.top() << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <ctype.h>
#include <stdio.h>
#define STACK 106

int main(void) {

  int stack[STACK];
  int n = 0, f = 0;
  int sum;

  int k;
  char ch;
  /*入力*/
  while ((ch = getchar()) != '\\n') {
    /*整数の場合*/
    if (isdigit(ch)) {
      /*整数が続いた場合*/
      if (f) {
        stack[n] = stack[n] * 10 + (ch - '0');
      } else {
        stack[n] = (ch - '0');
        f++;
      }
    }
    /*空白の場合*/
    if (isspace(ch)) {
      if (f) {
        n++;
        f = 0;
      }
    }
    /*足し算の場合’*/
    if (ch == '+') {

      if (n > 1) {
        n--;
      }
      stack[n - 1] += stack[n];
      stack[n] = 0;
    }
    /*引き算の場合*/
    if (ch == '-') {

      if (n > 1) {
        n--;
      }
      stack[n - 1] -= stack[n];
      stack[n] = 0;
    }
    /*掛け算の場合*/
    if (ch == '*') {

      if (n > 1) {
        n--;
      }
      stack[n - 1] *= stack[n];
      stack[n] = 0;
    }
  }
  /*出力*/
  printf("%d\\n", stack[0]);

  return 0;
}


Error: 0

Fixed submission:

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

#define SIZE 100
#define N 100
int cal(char *);
int get(char *);
void push(int);
int digit(char *);
double pop();
int s[SIZE];
int size = 0;
int main() {

  char s[N];

  scanf("%[^/n]*s", s);
  printf("%d\\n", cal(s));
  return 0;
}

void push(int a) {
  if (size < SIZE)
    s[size++] = a;
}

double pop() {
  if (size <= 0)
    return 0;
  return s[--size];
}

int digit(char *s) {

  if (*s == '+' || *s == '-') {
    s++;
    if (*s >= '0' && *s <= '9')
      return 1;
    return 0;
  }

  if (*s >= '0' && *s <= '9')
    return 1;
  return 0;
}

int get(char *s) {
  int hit = 0;
  int n = 0;

  if (*s == '+') {
    s++;
  }

  while (*s >= '0' && *s <= '9') {
    n = n * 10 + (*s - '0');
    s++;
  }
  if (hit == 1)
    return -n;

  return n;
}

int cal(char *s) {
  int a, b, n;

  while (*s) {

    if (digit(s)) {
      n = get(s);
      push(n);
      while (*s == '-' || *s == '+') {
        s++;
      }
      while (n) {
        n /= 10;
        s++;
      }
    } else {
      switch (*s) {
      case '+':
        a = pop();
        b = pop();
        push(a + b);
        break;

      case '-':
        a = pop();
        b = pop();
        push(b - a);
        break;

      case '*':
        a = pop();
        b = pop();
        push(b * a);
        break;
      }
      s++;
    }
  }
  return pop();
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stack>
#include <string>
#include <typeinfo>
using namespace std;
int main(void) {
  string num;
  int a, b;
  stack<int> st;
  while (cin >> num) {
    if (num == "+") {
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(a + b);
    } else if (num == "-") {
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b - a);
    } else if (num == "*") {
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(a * b);
    } else {
      st.push(stoi(num));
    }
  }
  cout << st.top() << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <stack>
using namespace std;
int main(void) {
  char num;
  int a, b;
  stack<int> st;
  for (int i = 0; i < 200; i++) {
    cin >> num;
    if (num == '+') {
      a = st.top();
      b = st.top();
      st.pop();
      st.pop();
      st.push(a + b);
    } else if (num == '-') {
      a = st.top();
      b = st.top();
      st.pop();
      st.pop();
      st.push(a - b);
    } else if (num == '*') {
      a = st.top();
      b = st.top();
      st.pop();
      st.pop();
      st.push(a * b);
    } else {
      st.push(num);
    }
  }
  cout << st.top() << endl;
  return 0;
}
Problem p02263 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstdlib>

using namespace std;

class Stack {
  int top = 0;
  int S[1000];

public:
  void push(int x) {
    top++;
    S[top] = x;
  }

public:
  int pop() {
    top--;
    return S[top + 1];
  }
};

int main() {
  int o1, o2;
  Stack stack;

  char s[100];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      o2 = stack.pop();
      o1 = stack.pop();
      stack.push(o1 + o2);
    } else if (s[0] == '-') {
      o2 = stack.pop();
      o1 = stack.pop();
      stack.push(o1 - o2);
    } else if (s[0] == '*') {
      o2 = stack.pop();
      o1 = stack.pop();
      stack.push(o1 * o2);
    } else {
      stack.push(atoi(s));
    }
  }

  printf("%d\\n", stack.pop());

  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <string>

using namespace std;

class Stack {
  int index = 0;
  int data[10];

public:
  void push(int x) {
    data[index] = x;
    index++;
  }

public:
  int pop() {
    index--;
    int r = data[index];
    return r;
  }
};

int main() {
  Stack stack;

  char tmp[6];
  while (scanf("%s", tmp)) {
    string s = tmp;
    if (s[0] == '+') {
      int o1 = stack.pop();
      int o2 = stack.pop();
      stack.push(o1 + o2);
    } else if (s[0] == '-') {
      int o1 = stack.pop();
      int o2 = stack.pop();
      stack.push(o1 ^ o2);
    } else if (s[0] == '*') {
      int o1 = stack.pop();
      int o2 = stack.pop();
      stack.push(o1 * o2);
    } else {
      int i = stoi(s);
      stack.push(i);
    }
  }

  printf("%d", stack.pop());

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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

#include <stack>
typedef long long ll;
typedef unsigned long long ull;

// size, top, pop, push, empty

int main() {

  stack<string> st;
  string str;

  while (cin >> str) {

    if (str == "+") {
      ll i2 = stoll(st.top());
      st.pop();
      ll i1 = stoll(st.top());
      st.pop();
      st.push(to_string(i1 + i2));
    } else if (str == "-") {
      ll i2 = stoll(st.top());
      st.pop();
      ll i1 = stoll(st.top());
      st.pop();
      st.push(to_string(i1 - i2));
    } else if (str == "*") {
      ll i2 = stoll(st.top());
      st.pop();
      ll i1 = stoll(st.top());
      st.pop();
      st.push(to_string(i1 * i2));
    } else {
      st.push(str);
    }
  }

  cout << st.top() << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include <map>
#include <queue>
#include <set>

#include <stack>
typedef long long ll;
typedef unsigned long long ull;

// size, top, pop, push, empty

int main() {

  int N;
  cin >> N;

  stack<ll> st;
  string str;
  while (cin >> str) {
    if (str == "+") {
      ll i1 = st.top();
      st.pop();
      ll i2 = st.top();
      st.pop();
      st.push(i1 + i2);
    } else if (str == "-") {
      ll i1 = st.top();
      st.pop();
      ll i2 = st.top();
      st.pop();
      st.push(i1 - i2);
    } else if (str == "*") {
      ll i1 = st.top();
      st.pop();
      ll i2 = st.top();
      st.pop();
      st.push(i1 * i2);
    } else {
      st.push(stoi(str));
    }
  }

  cout << st.top() << endl;
}