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

#include <stdio.h>

int main() {
  char b[15];
  while (~scanf("%s", b)) {
    int c[10];
    for (int i = 0; i < 10; i++)
      c[i] = b[i] - '0';
    for (int i = 9; i > 0; i--)
      for (int j = 0; j < i; j++)
        c[j] = (c[j] + c[j + 1]) % 10;
    printf("%d\\n", c[0]);
  }
}

Error: 0

Fixed submission:

#include <stdio.h>

int main() {
  char b[10];
  while (~scanf("%s", b)) {
    int c[10];
    for (int i = 0; i < 10; i++)
      c[i] = b[i] - '0';
    for (int i = 9; i > 0; i--)
      for (int j = 0; j < i; j++)
        c[j] = (c[j] + c[j + 1]) % 10;
    printf("%d\\n", c[0]);
  }
}
Problem p00062 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s1;
  int k[10][10];
  while (cin >> s1) {

    for (int i = 0; i < 10; i++)
      k[0][i] = s1[i] - '0';
    for (int i = 1; i < 10; i++) {
      for (int j = 0; j < 10 - i; j++) {
        k[i][j] = (k[i - 1][j] + k[i - 1][j + 1]) % 10;
        // cout<<k[i][j]<<i<<j;
      }
      // cout<<endl;
    }
    cout << k[9][0] << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s1;
  int k[10][10];
  while (cin >> s1) {
    for (int i = 0; i < 10; i++)
      k[0][i] = s1[i] - '0';
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10 - i; j++) {
        k[i + 1][j] = (k[i][j] + k[i][j + 1]) % 10;
        // cout<<k[i][j]<<i<<j;
      }
      // cout<<endl;
    }
    cout << k[9][0] << endl;
  }
}
Problem p00062 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
/*
int main(void)
{
        int botto[10];
        string inp;
        while(cin>>inp){
                for(int i=0;i<10;i++){
                        botto[i]=inp[i]-'0';
                }
                for(int i=0;i<10-1;i++){
                        for(int j=0;j<10-i-1;j++){
                                botto[j]=(botto[j]+botto[j+1])%10;
                        }
                }
                cout<<botto[0]<<endl;
        }
        return 0;
}
*/

int main(void) {
  int n[11] = {};
  string s;
  char ch;
  while (cin >> s) {
    for (int i = 0; i < 10; i++) {

      n[i] = s[i] - '0';
    }
    for (int k = 0; k < 10; k++)
      for (int i = 0; i < 10 - k - 1; i++)
        n[i] = (n[i] + n[i + 1]) % 10;

    cout << n[0] << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  char ch;
  string str;
  int NUM[11] = {}, NP[11][11] = {}, x, H = 1000000000;
  while (scanf("%d", &x) != EOF) {
    for (int i = 0; i < 10; i++) {
      if (i < 9) {
        NP[0][i] = x / H;
        H = H / 10;
      } else if (i == 9)
        NP[0][i] = x;
    }

    for (int i = 1; i < 7; i++)
      for (int j = 0; j < 7 - i; j++) {
        NP[i][j] = (NP[i - 1][j] + NP[i - 1][j + 1]) % 10;
      }

    printf("%d\\n", NP[9][0]);
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  string row, buf("");
  int a;
  char d;
  while (cin >> row, !cin.eof()) {
    for (int i = row.size(); i > 1; i--) {
      for (int j = 0; j < row.size() - 1; j++) {
        a = ((row.at(j) - '0') + (row.at(j + 1) - '0')) % 10;
        sprintf(&d, "%d", a);
        buf += d;
      }
      row = buf;
      buf = "";
    }
    cout << row << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int func(string row) {
  string buf;
  if (row.size() == 1) {
    return (int)row.at(0) - (int)'0';
  }
  for (int i = 0; i < row.size(); i++) {
    int a = (int)row.at(i) - (int)'0';
    int b = (int)row.at(i + 1) - (int)'0';
    int c = a + b % 10;
    char d;
    sprintf(&d, "%d", c);
    buf += d;
  }
  func(buf);
};

int main() {
  string row;
  while (cin >> row, !cin.eof()) {
    cout << func(row) << endl;
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char cnum[10];
  string ss;
  int num[10][10];
  while (cin >> ss) {
    // cin
    // >>cnum[0]>>cnum[1]>>cnum[2]>>cnum[3]>>cnum[4]>>cnum[5]>>cnum[6]>>cnum[7]>>cnum[8]>>cnum[9];
    if (cin.eof())
      break;
    for (int i = 0; i < 10; i++) {
      num[0][i] = (int)ss[i] - (int)'0';
    }
    for (int i = 1; i < 10; i++) // ツ行
    {
      for (int j = 0; j < 10 - i; j++) {
        num[i][j] = (num[i - 1][j] + num[i - 1][j + 1]) % 10;
      }
    }
    cout << num[9][0] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  char cnum[10];
  int num[10][10];
  while (1) {
    cin >> cnum[0] >> cnum[1] >> cnum[2] >> cnum[3] >> cnum[4] >> cnum[5] >>
        cnum[6] >> cnum[7] >> cnum[8] >> cnum[9];
    for (int i = 0; i < 10; i++) {
      num[0][i] = cnum[i] - '0';
    }
    for (int i = 1; i < 10; i++) // ツ行
    {
      for (int j = 0; j < 10 - i; j++) {
        num[i][j] = (num[i - 1][j] + num[i - 1][j + 1]) % 10;
      }
    }
    cout << num[9][0] << endl;
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  char tmp[10];
  char buf;
  while (cin >> buf) {
    tmp[0] = buf - '0';
    for (int i = 1; i < 10; i++) {
      cin >> buf;
      tmp[i] = buf - '0';
    }
    for (int i = 8; i >= 0; i--) {
      for (int j = 0; j <= i; j++) {
        tmp[j] = (tmp[j] + tmp[j + 1]) % 10;
      }
    }
    cout << (int)tmp[0] << endl;
  }
}

Error: 0

Fixed submission:

#include <cstdio>
int main() {
  char top[10];
  while (scanf("%s", top) != EOF) {
    int nums[10];
    for (int i = 0; i < 10; i++)
      nums[i] = top[i] - '0';
    int res = nums[0] + nums[1] * 9 + nums[2] * 36 + nums[3] * 84 +
              nums[4] * 126 + nums[5] * 126 + nums[6] * 84 + nums[7] * 36 +
              nums[8] * 9 + nums[9];
    res %= 10;
    printf("%d\\n", res);
  }
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int main() {
  char s[128], b[128];
  int l, r = 0;
  while (scanf("%s", s) != EOF) {
    l = strlen(s);
    strcpy(b, s);
    for (int i = 0; i < l; i++) {
      b[l - (i + 1)] = s[i];
    }
    if (strcmp(s, b) == 0) {
      r++;
    }
    for (int i = 0; i < 128; i++) {
      s[i] = 0;
      b[i] = 0;
    }
  }
  printf("%d\\n", r);
  return 0;
}

Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  char s[50], b[50];
  int l, r = 0;
  while (scanf("%s", s) != EOF) {
    l = strlen(s);
    strcpy(b, s);
    for (int i = 0; i < l; i++) {
      b[l - (i + 1)] = s[i];
    }
    if (strcmp(s, b) == 0) {
      r++;
    }
    for (int i = 0; i < 50; i++) {
      s[i] = 0;
      b[i] = 0;
    }
  }
  printf("%d\\n", r);
  return 0;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char ss[1000];
  int i, c;
  c = 0;
  while (0 <= scanf("%s", ss)) {
    for (i = 0; i <= strlen(ss) - 1; i++) {
      if (ss[i] != ss[strlen(ss) - i - 1])
        break;
    }

    if (i == strlen(ss))
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  char ss[100];
  int i, c;
  c = 0;
  i = 0;
  while (0 <= scanf("%s", ss)) {
    //	for(i=0;i<=strlen(ss)-1;i++){
    //		if(ss[i]!=ss[strlen(ss)-i-1])break;
    //	}

    if (i == strlen(ss) - 1)
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char ss[110];
  int i, c;
  c = 0;
  while (0 <= scanf("%s", ss)) {
    for (i = 0; i <= strlen(ss) - 1; i++) {
      if (ss[i] != ss[strlen(ss) - i - 1])
        break;
    }

    if (i == strlen(ss))
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  char ss[100];
  int i, c;
  c = 0;
  while (0 <= scanf("%s", ss)) {
    for (i = 0; i <= strlen(ss) - 1; i++) {
      if (ss[i] != ss[strlen(ss) - i - 1])
        break;
    }

    if (i == strlen(ss))
      ++c;
  }
  printf("%d\\n", c);
  return 0;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int c = 0, p = 0;
  while (cin >> s) {
    p++;
    for (int i = 0; i <= s.size() / 2; i++) {
      if (s[i] != s[s.size() - 1 - i]) {
        c++;
        break;
      }
    }
  }
  cout << p - c << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int c = 0;
  while (cin >> s) {
    int p = 1, q = 0;
    // if(s.size()%2)q=1;
    for (int i = 0; i < s.size() / 2 - 1; i++) {
      if (s[i] != s[s.size() - 1] - i)
        p = 0;
    }
    if (p)
      c++;
  }
  cout << c << endl;
}
Problem p00063 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  int count = 0;
  while (cin >> str) {
    bool b = true;
    int g = str.size();
    if (g % 2 == 0) {
      for (int i = 0; i < g; i++) {
        if (str[i] != str[g - 1 - i])
          b = false;
      }
      if (b != false)
        count++;
    } else {
      if (g == 1) {
        count++;
      } else {
        for (int i = 0; i < g; i++) {
          if (str[i] != str[g - i - 1])
            b = false;
        }
        if (b != false)
          count++;
      }
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string str;
  int sum = 0;
  while (cin >> str) {
    if (str.size() % 2 == 0) {
      for (int i = 0; i != str.size() / 2; i++) {
        if (str[i] != str[str.size() - i])
          continue;
      }
    } else {
      for (int i = 0; i != str.size() / 2 - 1; i++) {
        if (str[i] != str[str.size() - i])
          continue;
      }
    }
    sum++;
  }
  cout << sum << endl;
  char c;
  cin >> c;
}
Problem p00063 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string str, inv;
  int cnt = 0;
  while (getline(cin, str), str.length() != 0) {
    inv.resize(str.length());
    for (int i = 0; i < str.length(); i++) {
      inv[i] = str[str.length() - 1 - i];
    }
    if (str == inv) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  string str, inv;
  int cnt = 0;
  while (cin >> str, str.length()) {
    inv.resize(str.length());
    for (int i = 0; i < str.length(); i++) {
      inv[i] = str[str.length() - 1 - i];
    }
    if (str == inv) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char str[101];
  int count = 0;

  while (cin >> str) {
    int len = strlen(str);
    bool isPal = true;
    for (int i = 0; i < len / 2; i++) {
      if (str[i] != str[len - i - 1]) {
        isPal = false;
        break;
      }
    }
    if (isPal)
      count++;
  }

  cout << count << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  char str[51];
  int count = 0;

  while (cin >> str) {
    int len = strlen(str);
    bool isPal = true;
    for (int i = 0; i < len / 2; i++) {
      if (str[i] != str[len - i - 1]) {
        isPal = false;
        break;
      }
    }
    if (isPal)
      count++;
  }

  cout << count << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  string s1, s2;
  int cnt = 0;
  while (cin >> s1) {
    s2 = s1;
    reverse(s2.begin(), s2.end());
    if (s1 == s2)
      cnt++;
    // cnt += s1 == s2;
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;
int main(void) {
  char s1[100], s2[100];
  int len, cmp, cnt = 0;
  while (scanf("%s", s1) != EOF) {
    len = strlen(s1);
    for (int i = 0; i < len; i++) {
      s2[len - i - 1] = s1[i];
    }
    cmp = strcmp(s1, s2);
    if (cmp == 0)
      cnt++;
    // printf("%s %s\\n", s1, s2);
    for (int i = 0; i < 101; i++) {
      s2[i] = 0;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p00063 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(obj) ((int)(obj).size())

int main() {
  string str;
  int cnt = 0;
  while (cin >> str) {
    int ccnt = 0;
    REP(i, sz(str) / 2) if (str[i] == str[sz(str) - (i + 1)]) ccnt++;
    if (ccnt == sz(str) / 2)
      cnt++;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(obj) ((int)(obj).size())

int main() {
  string str;
  int cnt = 0;
  while (cin >> str, str[0] != EOF) {
    int ccnt = 0;
    REP(i, sz(str) / 2) {
      if (str[i] == str[sz(str) - (i + 1)])
        ccnt++;
      cout << ccnt << endl;
    }
    if (ccnt == sz(str) / 2)
      cnt++;
    cout << cnt << endl;
  }
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  int ans = 0;
  while (getline(cin, str)) {
    int len = str.size();
    string tmp = "";
    for (int i = len - 1; i >= 0; i--) {
      tmp += str[i];
    }
    if (str == tmp)
      ans++;
  }
  cout << ans << endl;
}

Error: -11

Fixed submission:

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

int main() {
  string str;
  int ans = 0;
  while (cin >> str) {
    int len = str.size();
    string tmp = "";
    for (int i = len - 1; i >= 0; i++) {
      tmp += str[i];
    }
    if (str == tmp)
      ans++;
  }
  cout << ans << endl;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  char str[200];
  int cnt = 0;

  while (scanf("%s", str) != EOF) {
    int i, j;
    for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) {
      if (str[i] != str[j])
        break;
    }
    if (i > j)
      cnt++;
  }

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

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  char str[100];
  int cnt = 0;

  while (scanf("%s", str) != EOF) {
    int i, j;
    for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) {
      if (str[i] != str[j])
        break;
    }
    if (i > j)
      cnt++;
  }

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

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

#include <cstdio>
#include <cstring>
#include <iostream>

int main() {
  char s1[101] = {0};
  char s2[101] = {0};
  int count = 0, flag = 0;

  while (scanf("%s", s1) != EOF) {
    int len = strlen(s1);
    /* if(len==1){
      count++;
      flag++;
      }*/
    for (int i = 0; i < len; i++) {
      s2[i] = s1[len - 1 - i];
    }
    s2[len] = '\\0';
    if (strcmp(s1, s2) == 0) {
      count++;
    }
    flag = 0;
  }

  printf("%d\\n", count);
  return (0);
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

int main() {
  char s1[51] = {0};
  char s2[51] = {0};
  int count = 0;

  while (scanf("%s", s1) != EOF) {
    int len = strlen(s1);
    for (int i = 0; i < len; i++) {
      s2[i] = s1[len - 1 - i];
    }
    if (strcmp(s1, s2) == 0) {
      count++;
    }
  }

  printf("%d\\n", count);
  return (0);
}
Problem p00063 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  string ins, rev;
  int ans = 0;
  while (cin >> ins) {
    rev = ins;
    reverse(rev.begin(), rev.end());
    if (ins == rev)
      ans++;
  }
  cout << ans << endl;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  string in;
  cin >> n >> in;
  vector<vector<int>> table(2, vector<int>(n + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (in[i - 1] == in[n - j])
        table[i % 2][j] = table[(i - 1) % 2][j - 1] + 1;
      else
        table[i % 2][j] = max(table[(i - 1) % 2][j], table[i % 2][j - 1]);
    }
  }
  cout << n - table[n % 2][n] << endl;
}
Problem p00063 (C++) — buggy submission, verdict: Runtime Error

// #define scanf_s scanf
#define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 101
int main(void) {
  char str[MAX];
  int i, j, cou = 0;
  while (gets_s(str) != NULL) {
    ++cou;
    for (i = 0; str[i] != '\\0'; ++i)
      ;
    for (j = 0; j < i / 2; ++j) {
      if (str[j] != str[i - 1 - j]) {
        --cou;
        break;
      }
    }
  }
  printf("%d\\n", cou);
}

Error: 0

Fixed submission:

#define scanf_s scanf
#define gets_s gets
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
#define MAX 51
int main(void) {
  char str[MAX];
  int i, j, cou = 0;
  while (scanf_s("%s", str) != EOF) {
    ++cou;
    for (i = 0; str[i] != '\\0'; ++i)
      ;
    for (j = 0; j < i / 2; ++j) {
      if (str[j] != str[i - 1 - j]) {
        --cou;
        break;
      }
    }
  }
  printf("%d\\n", cou);
}
Problem p00064 (C++) — buggy submission, verdict: Runtime Error

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define inf (1e9)
#define eps (1e-9)

int main() {
  string s;
  int ans = 0;
  while (getline(cin, s)) {
    transform(begin(s), end(s), begin(s),
              [](char c) { return isdigit(c) ? c : ' '; });
    stringstream ss(s);
    int x;
    while (ss >> x)
      ans += x;
  }
  cout << ans << endl;

  return 0;
}

Error: 0
>>> ss.str() =         100                 17                        6   


Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define loop for (;;)
#define trace(var) cerr << ">>> " << #var << " = " << var << endl;
#define inf (1e9)
#define eps (1e-9)

int main() {
  stringstream ss;
  char c;
  while (cin >> c)
    ss << (isdigit(c) ? c : ' ');
  trace(ss.str());
  int x;
  int ans = 0;
  while (ss >> x)
    ans += x;
  cout << ans << endl;

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

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
// #include<algorithm>
// #include<cmath>
// #include<string>
// #include<cctype>
// #include <vector>
using namespace std;
int main() {
  int s, a = 0;
  while (~scanf("%*[^0-9]%d", &s))
    a += s;
  cout << a << endl;
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
// #include<algorithm>
// #include<cmath>
// #include<string>
// #include<cctype>
// #include <vector>
using namespace std;
int main() {
  int s, a = 0;
  while (scanf("%*[^0-9]%d", &s) != 0)
    a += s;
  cout << a << endl;
  return 0;
}
Problem p00064 (C++) — buggy submission, verdict: Runtime Error

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

using db = double;
using ll = long long;
using vi = vector<int>;
#define op operator
#define pb push_back

int main() {
  cout << fixed << setprecision(9);
  ios ::sync_with_stdio(0);

  int ans = 0;
  for (string s; getline(cin, s);) {
    s += ' ';
    string t = "";
    for (char c : s)
      if (isdigit(c))
        t += c;
      else if (t.size()) {
        ans += stoi(t);
        t = "";
      }
  }
  cout << ans << '\\n';

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi


Fixed submission:

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

using db = double;
using ll = long long;
using vi = vector<int>;
#define op operator
#define pb push_back

int main() {
  cout << fixed << setprecision(9);
  ios ::sync_with_stdio(0);

  int ans = 0;
  for (string s; getline(cin, s);) {
    s += ' ';
    string t = "";
    for (char c : s)
      if (isdigit(c))
        t += c;
      else {
        ans += stoi(t);
        t = "";
      }
  }
  cout << ans << '\\n';

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

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int ans = 0;
  string s;
  while (cin >> s) {
    for (int i = 0; i < s.size(); i++) {
      int tmp = 0;
      while ((i < s.size()) && (s[i] < '0' || '9' < s[i]))
        i++;
      if (!(i < s.size()))
        continue;
      while ((i < s.size()) && (!(s[i] < '0' || '9' < s[i]))) {
        tmp = tmp * 10;
        tmp = tmp + int(s[i] - '0');
        i++;
      }
      ans = ans + tmp;
    }
  }
  cout << ans << endl;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int ans = 0;
  string s;
  while (cin >> s) {
    for (int i = 0; i < s.size(); i++) {
      int tmp = 0;
      while (s[i] < '0' || '9' < s[i])
        i++;
      if (!(i < s.size()))
        continue;
      while (!(s[i] < '0' || '9' < s[i])) {
        tmp = tmp * 10;
        tmp = tmp + int(s[i] - '0');
        i++;
      }
      cout << tmp << endl;
      ans = ans + tmp;
    }
  }
  cout << ans << endl;
}
Problem p00064 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge {
  int to, time, cost;
};
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

int sum = 0;
std::string str;
std::string::iterator it;

int number() {
  int ret = 0;
  while (isdigit(*it)) {
    ret *= 10;
    ret += (*it - '0');
    ++it;
  }
  return ret;
}

int main() {
  while (std::cin >> str) {
    str += ".";
    it = str.begin();
    while (it != str.end()) {
      if (isdigit(*it))
        sum += number();
      ++it;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for (int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge {
  int to, time, cost;
};
const double eps = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+17 + 10;
const double infd = (double)1e+9;

int sum = 0;
std::string str;
std::string::iterator it;

int number() {
  int ret = 0;
  while (isdigit(*it)) {
    ret *= 10;
    ret += (*it - '0');
    ++it;
  }
  return ret;
}

int main() {
  while (std::cin >> str) {
    it = str.begin();
    while (it != str.end()) {
      if (isdigit(*it))
        sum += number();
      ++it;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}