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

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

int main() {
  string s, str;
  string::size_type sz;
  while (getline(cin, str)) {
    vector<string> vec;
    vector<double> v;
    s = "";
    for (int i = 0; i < str.length(); i++) {
      while ((str[i] != ' ' && i < str.length()) ||
             (i < str.length() - 1 && str[i] == '-' && str[i + 1] >= '0' &&
              str[i] <= '9')) {
        s = s + str[i];
        i++;
      }
      vec.push_back(s);
      s = "";
    }
    vec.push_back(s);
    double a, b, t;
    for (int i = 0; i < vec.size(); i++) {
      if (vec[i].length() == 1 && (vec[i][0] < '0' || vec[i][0] > '9')) {
        a = v[v.size() - 2];
        b = v[v.size() - 1];
        if (vec[i][0] == '+')
          t = a + b;
        if (vec[i][0] == '-')
          t = a - b;
        if (vec[i][0] == '*')
          t = a * b;
        if (vec[i][0] == '/')
          t = a / b;
        v.pop_back();
        v.pop_back();
        v.push_back(t);
      } else {
        v.push_back(atof(vec[i].c_str()));
      }
    }
    printf("%.6f\\n", v[0]);
  }
}

Error: -6
double free or corruption (out)


Fixed submission:

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

int main() {
  string s, str;
  string::size_type sz;
  while (getline(cin, str)) {
    vector<string> vec;
    vector<double> v;
    s = "";
    for (int i = 0; i < str.length(); i++) {
      while ((str[i] != ' ' && i < str.length()) ||
             (i < str.length() - 1 && str[i] == '-' && str[i + 1] >= '0' &&
              str[i] <= '9')) {
        s = s + str[i];
        i++;
      }
      vec.push_back(s);
      s = "";
    }
    vec.push_back(s);
    double a, b, t;
    for (int i = 0; i < vec.size(); i++) {
      if ((vec[i][0] == '-' && vec[i].length() > 1) ||
          (vec[i][0] >= '0' && vec[i][0] <= '9'))
        v.push_back(atof(vec[i].c_str()));
      else {
        a = v[v.size() - 2];
        b = v[v.size() - 1];
        if (vec[i][0] == '+')
          t = a + b;
        if (vec[i][0] == '-')
          t = a - b;
        if (vec[i][0] == '*')
          t = a * b;
        if (vec[i][0] == '/')
          t = a / b;
        v.pop_back();
        v.pop_back();
        v.push_back(t);
      }
    }
    printf("%.6f\\n", v[0]);
  }
}
Problem p00087 (C++) — buggy submission, verdict: Runtime Error

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

stack<double> st;

double solve(char s) {
  double a, b;
  b = st.top();
  st.pop();
  a = st.top();
  st.pop();
  if (s == '+')
    return (a + b);
  else if (s == '-')
    return (a - b);
  else if (s == '*')
    return (a * b);
  else if (s == '/')
    return (a / b);
  return 1;
}

int main() {
  int cnt = 0;
  char s[80];
  while (1) {
  exit:
    cin >> s;
    cnt++;
    if (cin.eof())
      break;
    if (getchar() == '\\n') {
      if (cnt == 1) {
        cout << s << endl;
        cnt = 0;
        goto exit;
      }
      st.push(solve(s[0]));
      printf("%.6f\\n", st.top());
      st.pop();
      cnt = 0;
    } else if (!isalnum(s[0]) && !isalnum(s[1]))
      st.push(solve(s[0]));
    else
      st.push(atof(s));
  }
  return 0;
}

Error: -11

Fixed submission:

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

stack<double> st;

int solve(char s) {
  double a, b;
  b = st.top();
  st.pop();
  a = st.top();
  st.pop();
  if (s == '+')
    return (a + b);
  else if (s == '-')
    return (a - b);
  else if (s == '*')
    return (a * b);
  else if (s == '/')
    return (a / b);
  return 1;
}

int main() {
  char s[50];
  while (1) {
    cin >> s;
    if (cin.eof())
      break;
    if (getchar() == '\\n') {
      st.push(solve(s[0]));
      printf("%.6f\\n", st.top());
    } else if (!isalnum(s[0]))
      st.push(solve(s[0]));
    else
      st.push(atof(s));
  }
}
Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string a;
  while (getline(cin, a)) {
    bool hantei = true;
    stack<double> stk;
    while (hantei) {
      string b = "";
      while (true) {
        if (a[0] == ' ') {
          a = a.substr(1);
          break;
        } else if (a.size() == 1) {
          b += a[0];
          hantei = false;
          break;
        } else {
          b += a[0];
          a = a.substr(1);
        }
      }
      if (b == "+") {
        double p = stk.top();
        stk.pop();
        double q = stk.top();
        stk.pop();
        stk.push(p + q);
      } else if (b == "-") {
        double p = stk.top();
        stk.pop();
        double q = stk.top();
        stk.pop();
        stk.push(q - p);
      } else if (b == "*") {
        double p = stk.top();
        stk.pop();
        double q = stk.top();
        stk.pop();
        stk.push(p * q);
      } else if (b == "/") {
        double p = stk.top();
        stk.pop();
        double q = stk.top();
        stk.pop();
        stk.push(q / p);
      } else {
        double k;
        stringstream ss;
        ss << b;
        ss >> k;
        stk.push(k);
      }
    }
    printf("%.6f\\n", stk.top());
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
  string b;
  while (getline(cin, b)) {
    stack<double> stk;
    double counter = 0.0;
    bool hantei = false;
    for (int i = 0; i < b.size(); i++) {
      if (0 <= b[i] - '0' && b[i] - '0' <= 9) {
        hantei = true;
        counter *= 10.0;
        if (counter >= 0.0) {
          counter += b[i] - '0';
        } else {
          counter += -(b[i] - '0');
        }
      } else if (b[i] == ' ') {
        if (hantei) {
          stk.push(counter);
          counter = 0.0;
          hantei = false;
        }
      } else {
        if (b[i] != '-') {
          double s1, s2;
          s1 = stk.top();
          stk.pop();
          s2 = stk.top();
          stk.pop();
          if (b[i] == '+') {
            stk.push(s2 + s1);
          } else if (b[i] == '*') {
            stk.push(s2 * s1);
          } else if (b[i] == '/') {
            stk.push(s2 / s1);
          }
        } else if (b[i] == '-') {
          if (i != b.size() - 1 && 0 <= b[i + 1] - '0' && b[i + 1] - '0' <= 9) {
            hantei = true;
            counter += -(b[i + 1] - '0');
            i++;
          } else {
            double s1, s2;
            s1 = stk.top();
            stk.pop();
            s2 = stk.top();
            stk.pop();
            stk.push(s2 - s1);
          }
        }
      }
    }
    printf("%.6f\\n", stk.top());
  }
  return 0;
}
Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (s.size() == 0)
      return 0;

    istringstream iss(s);
    stack<double> stk;
    for (;;) {
      string s1;
      if (iss >> s1) {
        if (s1.size() > 1 || ('0' <= s1[0] && s1[0] <= '9'))
          stk.push(atof(s1.c_str()));
        else {
          double x = stk.top();
          stk.pop();
          double y = stk.top();
          stk.pop();
          if (s1 == "+")
            stk.push(y + x);
          else if (s1 == "-")
            stk.push(y - x);
          else if (s1 == "*")
            stk.push(y * x);
          else
            stk.push(y / x);
        }
      } else
        break;
    }
    printf("%.10f\\n", stk.top());
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    string s;
    getline(cin, s);
    if (s.size() == 0)
      return 0;

    istringstream iss(s);
    stack<double> stk;
    for (;;) {
      string s1;
      if (iss >> s1) {
        if ('0' <= s1[0] && s1[0] <= '9')
          stk.push(atof(s1.c_str()));
        else {
          double x = stk.top();
          stk.pop();
          double y = stk.top();
          stk.pop();
          if (s1 == "+")
            stk.push(y + x);
          else if (s1 == "-")
            stk.push(y - x);
          else if (s1 == "*")
            stk.push(y * x);
          else
            stk.push(y / x);
        }
      } else
        break;
    }
    printf("%.10f\\n", stk.top());
  }
}
Problem p00087 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  stack<double> st;
  double a, b;
  char s[105];
  char w;
  while (~scanf("%s%c", s, &w)) {
    switch (s[0]) {
    case '+':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b + a);
      break;
    case '-':
      if (s[1] != '\\0')
        goto a;
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b - a);
      break;
    case '*':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b * a);
      break;
    case '/':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b / a);
      break;
    default:
    a:
      sscanf(s, "%lf", &a);
      st.push(a);
    }
    if (w == '\\n') {
      printf("%.5lf\\n", st.top());
      while (!st.empty())
        st.pop();
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main() {
  stack<double> st;
  double a, b;
  char s[105];
  char w;
  while (~scanf("%s%c", s, &w)) {
    switch (s[0]) {
    case '+':
      if (st.size() < 2)
        return 0;
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b + a);
      break;
    case '-':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b - a);
      break;
    case '*':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b * a);
      break;
    case '/':
      a = st.top();
      st.pop();
      b = st.top();
      st.pop();
      st.push(b / a);
      break;
    default:
      sscanf(s, "%lf", &a);
      st.push(a);
    }
    if (w == '\\n') {
      cout << st.top() << endl;
      while (!st.empty())
        st.pop();
    }
  }
  return 0;
}
Problem p00088 (C++) — buggy submission, verdict: Runtime Error

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

const string table[] = {
    "100101",   "10011010", "0101",     "0001",     "110",      "01001",
    "10011011", "010000",   "0111",     "10011000", "0110",     "00100",
    "10011001", "10011110", "00101",    "111",      "10011111", "1000",
    "00110",    "00111",    "10011100", "10011101", "000010",   "10010010",
    "10010011", "10010000",
};

void out(const string &s) {
  int n = strtol(s.substr(0, 5).c_str(), 0, 2);
  if (n < 26)
    putchar(n + 'A');
  else
    putchar(" .,-'?"[n - 26]);
}

int main() {
  char c;
  string s;
  for (; c = getchar(), c != EOF;) {
    switch (c) {
    case '\\n':
      if (s.length() > 0) {
        s += "0000";
        out(s);
      }
      puts("");
      s = "";
      break;
    case ' ':
      s += "101";
      break;
    case '\\'':
      s += "000000";
      break;
    case ',':
      s += "000011";
      break;
    case '-':
      s += "10010001";
      break;
    case '.':
      s += "010001";
      break;
    case '?':
      s += "000001";
      break;
    default:
      s += table[c - 'A'];
      break;
    }
    while (s.length() > 4) {
      out(s);
      s = s.substr(5);
    }
  }
}

Error: 0

Fixed submission:

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

const string table[] = {
    "100101",   "10011010", "0101",     "0001",     "110",      "01001",
    "10011011", "010000",   "0111",     "10011000", "0110",     "00100",
    "10011001", "10011110", "00101",    "111",      "10011111", "1000",
    "00110",    "00111",    "10011100", "10011101", "000010",   "10010010",
    "10010011", "10010000",
};

void out(const string &s) {
  int n = strtol(s.substr(0, 5).c_str(), 0, 2);
  if (n < 26)
    putchar(n + 'A');
  else
    putchar(" .,-'?"[n - 26]);
}

int main() {
  char c;
  string s;
  for (; c = getchar(), c != EOF;) {
    switch (c) {
    case '\\n':
      if (s.length() > 0) {
        s += "0000" + (s.length() - 1);
        out(s);
      }
      puts("");
      s = "";
      break;
    case ' ':
      s += "101";
      break;
    case '\\'':
      s += "000000";
      break;
    case '-':
      s += "10010001";
      break;
    case '.':
      s += "010001";
      break;
    case '?':
      s += "000001";
      break;
    default:
      s += table[c - 'A'];
      break;
    }
    while (s.length() > 4) {
      out(s);
      s = s.substr(5);
    }
  }
}
Problem p00088 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {"100101",   "10011010", "0101",     "0001",     "110",
                     "01001",    "10011011", "010000",   "0111",     "10011000",
                     "0110",     "00100",    "10011001", "10011110", "00101",
                     "111",      "10011111", "1000",     "00110",    "00111",
                     "10011100", "10011101", "000010",   "10010010", "10010011",
                     "10010000", "101",      "010001",   "000011",   "10010001",
                     "000000",   "000001"};
vector<string> s2 = {
    "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
    "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
    "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
    "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"};
string s;
int main() {
  while (s = "", getline(cin, s)) {
    string t;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < e.size(); j++) {
        if (s[i] == e[j])
          t += s1[j];
      }
    }
    while (t.size() % 5 != 0)
      t += "0";
    string ret = "";
    for (int i = 0; i < t.size(); i += 5) {
      string u = t.substr(i, 5);
      for (int j = 0; j < e.size(); j++) {
        if (u == s2[j])
          ret += e[j];
      }
    }
    cout << ret << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {"100101",   "10011010", "0101",     "0001",     "110",
                     "01001",    "10011011", "010000",   "0111",     "10011000",
                     "0110",     "00100",    "10011001", "10011110", "00101",
                     "111",      "10011111", "1000",     "00110",    "00111",
                     "10011100", "10011101", "000010",   "10010010", "10010011",
                     "10010000", "101",      "010001",   "000011",   "10010001",
                     "000000",   "000001"};
vector<string> s2 = {
    "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111",
    "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111",
    "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111",
    "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"};
string s;
int main() {
  while (true) {
    s = "";
    while (s == "")
      getline(cin, s);
    string t;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 0; j < e.size(); j++) {
        if (s[i] == e[j])
          t += s1[j];
      }
    }
    while (t.size() % 5 != 0)
      t += "0";
    string ret = "";
    for (int i = 0; i < t.size(); i += 5) {
      string u = t.substr(i, 5);
      for (int j = 0; j < e.size(); j++) {
        if (u == s2[j])
          ret += e[j];
      }
    }
    cout << ret << endl;
  }
  return 0;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int n[99][50], m[99][50];
string s[100];

int main() {
  int l = 0;
  while (getline(cin, s[l]))
    l++;
  for (int i = 0; i < l; i++) {
    int pos = 0, cur = 0;
    while (pos < s[i].size()) {
      if (isdigit(s[i][pos]))
        n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0';
      else
        cur++;
      pos++;
    }
  }
  m[0][0] = n[0][0];
  for (int i = 1; i <= l / 2; i++) {
    m[i][0] = m[i - 1][0] + n[i][0];
    m[i][i] = m[i - 1][i - 1] + n[i][i];
    for (int j = 1; j < i; j++)
      m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j];
  }
  for (int i = l / 2 + 1; i < l; i++) {
    for (int j = 0; j < l - i; j++) {
      m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j];
    }
  }
  cout << m[l - 1][0] << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int n[99][50], m[99][50];
string s[99];

int main() {
  int l = 0;
  while (getline(cin, s[l]))
    l++;
  for (int i = 0; i < l; i++) {
    int pos = 0, cur = 0;
    while (pos < s[i].size()) {
      if (isdigit(s[i][pos]))
        n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0';
      else
        cur++;
      pos++;
    }
  }
  m[0][0] = n[0][0];
  for (int i = 1; i <= l / 2; i++) {
    m[i][0] = m[i - 1][0] + n[i][0];
    m[i][i] = m[i - 1][i - 1] + n[i][i];
    for (int j = 1; j < i; j++)
      m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j];
  }
  for (int i = l / 2 + 1; i < l; i++) {
    for (int j = 0; j < l - i; j++) {
      m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j];
    }
  }
  cout << m[l - 1][0] << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, pair<int, int>> NODE;
#define SUM first
#define Y second.first
#define X second.second
#define ppp(a, b, c) make_pair(a, make_pair(b, c))
int main() {
  int a;
  char b;
  int u = 0;
  int mx = 0;
  int ret = 0;
  int done[100][100];
  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      done[i][j] = -1;
  vector<deque<int>> data(1);
  while (~scanf("%d%c", &a, &b)) {
    if (b == ',') {
      data[u].push_back(a);
    } else {
      data[u].push_back(a);
      mx = max<int>(data[u].size(), mx);
      if (data[u].size() < mx) {
        int tmp = data[u].size();
        for (int i = 0; i < mx - tmp; i++) {
          data[u].push_front(-1);
          data[u].push_back(-1);
        }
      }
      u++;
      data.resize(data.size() + 1);
    }
  }
  /*for(int i=0;i<data.size();i++){
  for(int j=0;j<data[i].size();j++){
          printf("%3d",data[i][j]);
  }
  cout << endl;
  }
  */
  queue<NODE> Q;
  Q.push(ppp(data[0][0], 0, 0));
  while (Q.size()) {
    NODE q = Q.front();
    Q.pop();
    if (q.SUM <= done[q.Y][q.X]) {
      continue;
    } else {
      done[q.Y][q.X] = q.SUM;
    }
    if (data[q.Y + 1].empty()) {
      ret = max(ret, q.SUM);
      continue;
    }
    if (~data[q.Y + 1][q.X])
      Q.push(ppp(q.SUM + data[q.Y + 1][q.X], q.Y + 1, q.X));
    if (~data[q.Y + 1][q.X + 1])
      Q.push(ppp(q.SUM + data[q.Y + 1][q.X + 1], q.Y + 1, q.X + 1));
  }
  /*for(int i=0;i<data.size();i++){
  for(int j=0;j<data[i].size();j++){
          printf("%3d",done[i][j]);
  }
  cout << endl;
  }*/
  cout << ret << endl;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

vector<vector<int>> con;
vector<vector<int>> super;
vector<string> str;
string t, atoato;
int ret, MX;
vector<int> dp(201, 1 << 21);
void saiki(int y, int x, int now, int deep) {
  now += super[y][x];
  if (dp[deep + 15] >= now)
    dp[deep] = now;
  else
    return;

  if (y == con.size() - 1 && x == MX) {
    ret = max(now, ret);
    return;
  }
  if (super[y + 1][x - 1] != -1)
    saiki(y + 1, x - 1, now, deep + 1);
  if (super[y + 1][x + 1] != -1)
    saiki(y + 1, x + 1, now, deep + 1);
  return;
}

int main() {
  int loop = 0;
  while (cin >> t) {
    con.resize(str.size() + 1);
    str.push_back(t);
    t += ',';
    for (int i = 0; i < t.length(); i++) {
      if (t[i] == ',') {
        con[loop].push_back(atoi(atoato.c_str()));
        atoato.clear();
      } else {
        atoato += t[i];
      }
    }
    MX = max<int>(MX, con[loop].size());
    loop++;
  }
  super.resize(con.size());
  for (int i = 0; i < con.size(); i++) {
    for (int j = 0; j < MX - con[i].size() + 1; j++) {
      super[i].push_back(-1);
    }
    for (int j = 0; j < con[i].size(); j++) {
      if (j)
        super[i].push_back(-1);
      super[i].push_back(con[i][j]);
    }
    for (int j = 0; j < MX - con[i].size() + 1; j++) {
      super[i].push_back(-1);
    }
  }
  saiki(0, MX, 0, 0);
  cout << ret << endl;
}
Problem p00089 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string s;
  int num = 0;
  vector<int> rhombus;

  // Input
  while (cin >> s) {
    for (int i = 0; i < s.size(); i++) {
      int n = s[i++] - '0';
      while ('0' <= s[i] && s[i] <= '9')
        n = n * 10 + (s[i++] - '0');

      rhombus.push_back(n);
      num++;
    }
  }

  int index = 1;
  for (int i = 2; i * i <= num; i++) {
    rhombus[index] += rhombus[index - i + 1];
    index++;
    for (int j = 1; j <= i - 2; j++) {
      rhombus[index] += max(rhombus[index - i], rhombus[index - i + 1]);
      index++;
    }
    rhombus[index] += rhombus[index - i];
    index++;
  }
  for (int i = sqrt(num) - 1; i > 0; i--) {
    for (int j = 0; j < i; j++) {
      rhombus[index] += max(rhombus[index - i - 1], rhombus[index - i]);
      index++;
    }
  }

  cout << rhombus[num - 1] << endl;

  return 0;
}

Error: 0
7
3,8
8,1,0
2,7,4,4
4,5,2,6,5
2,7,4,4
8,1,0
3,8
7


Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string s;
  int num = 0;
  vector<int> rhombus;

  // Input
  while (cin >> s) {
    cerr << s << endl;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == ',')
        continue;
      rhombus.push_back((int)(s[i] - '0'));
      num++;
    }
  }

  int index = 1;
  for (int i = 2; i * i <= num; i++) {
    rhombus[index] += rhombus[index - i + 1];
    index++;
    for (int j = 1; j < i - 1; j++) {
      rhombus[index] += max(rhombus[index - i], rhombus[index - i + 1]);
      index++;
    }
    rhombus[index] += rhombus[index - i];
    index++;
  }
  for (int i = sqrt(num) - 1; i > 0; i--) {
    for (int j = 0; j < i; j++) {
      rhombus[index] += max(rhombus[index - i - 1], rhombus[index - i]);
      index++;
    }
  }

  cout << rhombus[num - 1] << endl;

  return 0;
}