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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef pair<int, int> ii;

int main() {
  vector<ii> ts;
  int id, solve;
  while (scanf("%d,%d", &id, &solve), id | solve) {
    ts.push_back(make_pair(solve, id));
  }
  sort(ts.begin(), ts.end(), greater<ii>());
  map<int, int> rs;
  int rank = 0;
  int pre = -1;
  for (vector<pair<int, int>>::iterator it = ts.begin(); it != ts.end(); it++) {
    if (it->first == pre) {
      rs[it->second] = rank;
    } else {
      rs[it->second] = ++rank;
      pre = it->first;
    }
  }
  while (cin >> id) {
    cout << rs[id] << endl;
  }
}

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


Fixed submission:

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

class Team {
public:
  int id_;
  int solve_;
  int rank_;

  Team(int id, int solve) {
    id_ = id;
    solve_ = solve;
  }
};

bool moreSolve(const Team &t1, const Team &t2) { return t1.solve_ > t2.solve_; }

bool lessId(const Team &t1, const Team &t2) { return t1.id_ < t2.id_; }

int main() {
  while (true) {
    vector<Team> teams;
    int id, solve;
    while (scanf("%d,%d", &id, &solve), id && solve) {
      teams.push_back(Team(id, solve));
    }

    sort(teams.begin(), teams.end(), moreSolve);
    teams[0].rank_ = 1;
    solve = teams[0].solve_;
    for (int i = 1, size = teams.size(); i < size; i++) {
      if (teams[i].solve_ == solve) {
        teams[i].rank_ = teams[i - 1].rank_;
      } else {
        teams[i].rank_ = teams[i - 1].rank_ + 1;
        solve = teams[i].solve_;
      }
    }

    sort(teams.begin(), teams.end(), lessId);
    while (cin >> id) {
      for (vector<Team>::iterator it = teams.begin(); it != teams.end(); it++) {
        if (it->id_ == id) {
          cout << it->rank_ << endl;
        }
      }
    }
  }
}
Problem p00061 (C++) — buggy submission, verdict: Runtime Error

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

typedef pair<int, int> P;

int main() {
  int num, solve;
  vector<P> v;

  while (true) {
    scanf("%d,%d", &num, &solve);
    if (!num && !solve)
      break;
    v.push_back(P(-solve, num));
  }
  sort(v.begin(), v.end());

  int select;
  while (cin >> select) {
    int cnt = 1;
    for (int i = 0; i < v.size(); i++) {
      if (i && v[i].first != v[i - 1].first)
        cnt++;
      if (v[i].second == select)
        break;
    }
    cout << cnt << endl;
  }

  return 0;
}

Error: WA

Fixed submission:

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

int main(void) {
  pair<int, int> p[101];
  int num, point, i = 0;
  char cm;

  while (1) {
    cin >> num >> cm >> point;
    if (num == 0 && point == 0)
      break;

    p[i] = make_pair(-point, num);
    i++;
  }

  sort(p, p + i);

  int key;
  while (cin >> key) {
    int cnt = 1;
    for (int j = 1; p[j].second != key; j++) {
      if ((-1) * p[j].first != (-1) * p[j - 1].first)
        cnt++;
    }
    cout << cnt << endl;
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int team[200][3] = {{0}};
  int a, b;
  int cnt = 0;
  for (int i = 1; scanf("%d,%d", &a, &b); i++) {
    if (a + b == 0)
      break;
    team[i][0] = a, team[i][1] = b;
    cnt++;
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = i; j <= cnt; j++) {
      if (team[i][1] < team[j][1]) {
        swap(team[i][0], team[j][0]);
        swap(team[i][1], team[j][1]);
      }
    }
  }
  team[1][2] = 1;
  int rank = 1;
  for (int i = 2; i <= cnt; i++) {
    if (team[i - 1][1] > team[i][1])
      rank++;
    team[i][2] = rank;
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 1; i <= cnt; i++) {
      if (team[i][0] == n) {
        ans = team[i][2];
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
struct date {
  int team, point, rank;
};
int main() {
  int n, m;
  date a[300];
  int k = 1;
  while (scanf("%d,%d", &n, &m), n, m) {
    a[k].team = n, a[k].point = m;
    k++;
  }
  k--;
  int t[300] = {0};
  int l = 0;
  for (; scanf("%d", &t[l]) != EOF; l++)
    ;
  for (int i = 1; i <= k; i++) {
    for (int j = i; j <= k; j++) {
      if (a[i].point < a[j].point)
        swap(a[i], a[j]);
    }
  }

  a[1].rank = 1;
  for (int i = 2; i <= k; i++) {
    if (a[i].point == a[i - 1].point) {
      a[i].rank = a[i - 1].rank;
    } else
      a[i].rank = a[i - 1].rank + 1;
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      if (a[i].team < a[j].team)
        swap(a[i], a[j]);
    }
  }
  for (int i = 0; i < l; i++) {
    cout << a[t[i]].rank << endl;
  }
  return 0;
}
Problem p00061 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<int, int> a[1000];
  int c = 0, t[1000];
  char cc;
  while (1) {
    scanf("%d,%d", &a[c].second, &a[c].first);
    c++;
    if (a[c - 1].first == 0 && a[c - 1].second == 0)
      goto L;
  }
L:
  c--;
  stable_sort(a, a + c);
  int r = 1;
  t[a[c - 1].second] = 1;
  for (int i = c - 2; i >= 0; i--) {
    if (a[i + 1].first != a[i].first) {
      t[a[i].second] = (++r);
    } else {
      t[a[i].second] = r;
    }
  }
  while (cin >> c)
    cout << t[c] << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  pair<int, int> a[1000];
  int c = 0, t[1000];
  char cc;
  while (1) {
    scanf("%d,%d", &a[c].second, &a[c].first);
    c++;
    if (a[c - 1].first == 0 && a[c - 1].second == 0)
      goto L;
  }
L:
  c--;
  stable_sort(a, a + c);
  int r = 1;
  t[a[c - 1].second] = 1;
  for (int i = c - 2; i >= 0; i--) {
    if (a[i + 1].first != a[i].first) {
      t[a[i].second] = (++r);
    } else {
      t[a[i].second] = r;
    }
  }
  while (cin >> c, c)
    cout << t[c] << endl;
}
Problem p00061 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int id, num;
  map<int, int> m;
  vector<int> v;
  while (1) {
    scanf("%d,%d", &id, &num);
    if (id | num)
      ;
    else
      break;
    m[id] = num;
    v.push_back(-num);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  while (scanf("%d", &id) != EOF) {
    cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main() {
  int id, num;
  map<int, int> m;
  vector<int> v;
  while (1) {
    scanf("%d,%d", &id, &num);
    if (id | num)
      ;
    else
      break;
    m[id] = num;
    v.push_back(-num);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  while (scanf("%d", &id)) {
    cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl;
  }
  return 0;
}
Problem p00061 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <list>
#include <stdio.h>
#include <vector>

using namespace std;

list<int> l[31];

int main() {
  int ord, v, i;
  while (1) {
    scanf("%d,%d", &ord, &v);
    if (ord == 0 && v == 0)
      break;
    l[v].push_back(ord);
  }
  v = 1;
  while (scanf("%d", &ord) != EOF) {
    for (i = 30, v = 1; i > -1; i--) {
      list<int>::iterator it = l[i].begin();
      while (it != l[i].end()) {
        if (*it == ord) {
          printf("%d\\n", v);
          goto find;
        }
        it++;
      }
      if (!l[i].empty())
        v++;
    }
  find:;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <list>
#include <stdio.h>
#include <vector>

using namespace std;

list<int> l[30];

int main() {
  int ord, v, i, size;
  while (1) {
    scanf("%d,%d", &ord, &v);
    if (ord == 0 && v == 0)
      break;
    l[v - 1].push_back(ord);
  }
  v = 1;
  while (scanf("%d", &ord) != EOF) {
    for (i = 29, v = 1; i > -1; i--) {
      size = l[i].size();
      list<int>::iterator it = l[i].begin();
      while (it != l[i].end()) {
        if (*it == ord) {
          printf("%d\\n", v);
          goto find;
        }
        it++;
      }
      if (!l[i].empty())
        v++;
    }
  find:;
  }
  return 0;
}
Problem p00061 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int number, suu, in;
  // result = 整理番号と正解数の対応
  map<int, int> result;
  // rank = 順位表   need to include <functional>
  set<int, greater<int>> rank;

  while (scanf("%d,%d", &number, &suu), number || suu) {
    result.insert(std::pair<int, int>(number, suu));
    rank.insert(suu);
  }
  while (cin >> in, !cin.eof()) {
    // 整理番号が入力されるのでresultで正解数調べてrankを参照する.

    int place = 0;
    set<int>::iterator it = rank.begin();
    // set<int> rank; のときに
    //   set<int>::reverse_iretator it = rank.rbegin();とする方法もある.

    int thisSuu = result[in];
    // mapは[]使える. 以下は[]じゃなくiterator使う方法.
    // map<int, int>::iterator it_map = result.find(in);
    // int thisSuu = (*it_map).second;

    while (it != rank.end()) {
      place++;
      if (thisSuu == *it) {
        cout << place << endl;
        break;
      }
      it++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int number, suu, in;
  // result = 整理番号と正解数の対応
  map<int, int> result;
  // rank = 順位表   need to include <functional>
  set<int, greater<int>> rank;

  while (scanf("%d,%d", &number, &suu), number && suu) {
    result.insert(std::pair<int, int>(number, suu));
    rank.insert(suu);
  }
  while (cin >> in, !cin.eof()) {
    // 整理番号が入力されるのでresultで正解数調べてrankを参照する.

    int place = 0;
    set<int>::iterator it = rank.begin();
    // set<int> rank; のときに
    //   set<int>::reverse_iretator it = rank.rbegin();とする方法もある.

    int thisSuu = result[in];
    // mapは[]使える. 以下は[]じゃなくiterator使う方法.
    // map<int, int>::iterator it_map = result.find(in);
    // int thisSuu = (*it_map).second;

    while (it != rank.end()) {
      place++;
      if (thisSuu == *it) {
        cout << place << endl;
        break;
      }
      it++;
    }
  }
  return 0;
}
Problem p00061 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <queue>
#include <stdio.h>

using namespace std;

int main() {

  int data[101];
  int flag[31];

  for (int i = 0; i <= 30; i++) {
    flag[i] = 0;
  }
  int cnt = 0;
  data[0] = 0;
  while (1) {
    int num, ansNum;
    scanf("%d,%d", &num, &ansNum);

    if (num == 0 && ansNum == 0)
      break;
    cnt++;

    data[num] = ansNum;
  }

  int i;
  while (cin >> i) {
    int ans = 1;
    int tmpNum = 0;
    for (int j = 0; j <= 30; j++) {
      flag[j] = 0;
    }
    for (int j = 0; j <= cnt; j++) {
      if (i == j)
        continue;

      if (data[j] >= 0 && data[i] < data[j] && flag[data[j]] == 0) {
        ans++;
        flag[data[j]]++;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <queue>
#include <stdio.h>

using namespace std;

int main() {

  int data[101];
  int flag[31];

  for (int i = 0; i <= 30; i++) {
    flag[i] = 0;
  }
  int cnt = 0;
  data[0] = 0;
  while (1) {
    int num, ansNum;
    scanf("%d,%d", &num, &ansNum);

    if (num == 0 && ansNum == 0)
      break;
    cnt++;

    data[num] = ansNum;
  }

  while (1) {
    int i;
    cin >> i;
    int ans = 1;
    int tmpNum = 0;
    for (int j = 0; j <= 30; j++) {
      flag[j] = 0;
    }
    for (int j = 0; j < cnt; j++) {
      if (i == j)
        continue;

      if (data[i] < data[j] && flag[data[j]] == 0) {
        ans++;
        flag[data[j]]++;
      }
    }
    cout << ans << endl;
  }

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

#include <algorithm>
#include <stdio.h>
using namespace std;
pair<int, int> table[100000];
int COUNT[31];
int main() {
  int a, b;
  int index = 0;
  while (scanf("%d,%d", &a, &b), a + b) {
    table[index++] = make_pair(a, b);
    COUNT[b]++;
  }
  std::sort(table, table + index);
  int c;
  while (~scanf("%d", &c)) {
    int at = lower_bound(table, table + index, make_pair(c, 0)) - table;
    int sum = 0;
    for (int i = table[at].second + 1; i <= 30; i++)
      if (COUNT[i])
        sum++;
    printf("%d\\n", sum + 1);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
pair<int, int> table[100000];
int COUNT[31];
int main() {
  int a, b;
  int index = 0;
  while (scanf("%d,%d", &a, &b), a + b) {
    table[index++] = make_pair(a, b);
    COUNT[b]++;
  }
  std::sort(table, table + index);
  int c;
  while (~scanf("%d", &c), c) {
    int at = lower_bound(table, table + index, make_pair(c, 0)) - table;
    int sum = 0;
    for (int i = table[at].second + 1; i <= 30; i++)
      sum += COUNT[i];
    printf("%d\\n", sum + 1);
  }
}
Problem p00061 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

map<int, int> team;
priority_queue<int> score;
priority_queue<int> score2;

int main(void) {
  int a, b;
  while (1) {
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0)
      break;
    team.insert(map<int, int>::value_type(a, b));
    score.push(b);
  }
  while (~scanf("%d", &a)) {
    int t;
    int rank = 1;
    t = team[a];
    score2 = score;
    bool ch = true;
    while (ch) {
      int Us = 0;
      if (t == score2.top()) {
        cout << rank << endl;
        ch = false;
      }
      Us = score2.top();
      score2.pop();
      if (score2.top() != Us)
        rank++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

map<int, int> team;
priority_queue<int> score;
priority_queue<int> score2;

int main(void) {
  while (1) {
    int a, b;
    scanf("%d,%d", &a, &b);
    if (a == 0 && b == 0)
      break;
    team.insert(map<int, int>::value_type(a, b));
    score.push(b);
  }
  while (1) {
    int a, t;
    int rank = 1;
    scanf("%d", &a);
    if (a == 0)
      break;
    t = team[a];
    score2 = score;
    bool ch = true;
    while (ch) {
      int Us = 0;
      if (t == score2.top()) {
        cout << rank << endl;
        ch = false;
      }
      Us = score2.top();
      score2.pop();
      if (score2.top() != Us)
        rank++;
    }
  }
  return 0;
}
Problem p00061 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstdio>
#include <map>

using namespace std;

int main() {
  bool ans[31] = {false};
  map<int, int> data;
  int id, score;
  for (int i = 0; ~scanf("%d,%d", &id, &score), id || score; i++) {
    ans[score] = true;
    data.insert(make_pair(id, score));
  }

  int rank[31];
  for (int i = 30, r = 1; i >= 0; i--) {
    if (ans[i])
      rank[i] = r++;
  }

  while (~scanf("%d", &id))
    printf("%d\\n", rank[data[id]]);

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef pair<int, int> pii;

int main() {
  vector<pii> data;
  int id_max = 0;
  for (int i = 0;; i++) {
    int id, score;
    id_max = max(id_max, id);
    scanf("%d,%d", &id, &score);
    if (id == 0 && score == 0)
      break;
    data.push_back(make_pair(score, id));
  }

  sort(data.begin(), data.end(), greater<pii>());

  vector<int> rank(id_max);
  rank[data[0].second] = 1;
  int score_bef = data[0].first;
  for (int i = 1, r = 1; i < data.size(); i++) {
    if (data[i].first < score_bef)
      r++;
    rank[data[i].second] = r;
    score_bef = data[i].first;
  }

  int n;
  while (~scanf("%d", &n))
    printf("%d\\n", rank[n]);

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

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char input[20];
  int field[20][20];

  while (scanf("%s", input) != EOF) {
    memset(field, 0, sizeof(field));

    for (int i = 0; i < 9; i++) {
      field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10;
    }

    for (int i = 1; i < 9; i++) {
      for (int j = 0; j <= 8 - i; j++) {
        if (j < 0)
          break;
        field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10;
      }
    }
    /*for(int i = 0 ; i < 9 ; i++) {
      for(int j = 0 ; j <= 8-i ; j++) {
      cout << field[i][j] << ' ';
        }
      cout << endl;
      }
    cout << endl;*/
    cout << field[8][0] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char input[10];
  int field[9][9];

  while (scanf("%s", input) != EOF) {
    memset(field, 0, sizeof(field));

    for (int i = 0; i < 9; i++) {
      field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10;
    }

    for (int i = 1; i < 9; i++) {
      for (int j = 0; j <= 8 - i; j++) {
        if (j < 0)
          break;
        field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10;
      }
    }
    /*for(int i = 0 ; i < 9 ; i++) {
      for(int j = 0 ; j <= 8-i ; j++) {
      cout << field[i][j] << ' ';
        }
      cout << endl;
      }
    cout << endl;*/
    cout << field[8][0] << endl;
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  string num1;
  int num[10];
  int ans[10];
  int a, b;
  while (cin >> num1) {
    for (a = 0; a < 10; a++) {
      num[a] = num1[a] - '0';
    }
    for (a = 0; a < 10; a++) {
      for (b = 0; b < 9 - a; b++) {
        ans[b] = (num[b] + num[b + 1]) % 10;
      }
      for (b = 0; b < 9 - a; b++) {
        num[b] = ans[b];
      }
    }
    printf("%d\\n", ans[0]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  char num1[10];
  int num[10];
  int ans[10];
  int a, b;
  while (cin >> num1) {
    for (a = 0; a < 10; a++) {
      num[a] = num1[a] - '0';
    }
    for (a = 0; a < 10; a++) {
      for (b = 0; b < 9 - a; b++) {
        ans[b] = (num[b] + num[b + 1]) % 10;
      }
      for (b = 0; b < 9 - a; b++) {
        num[b] = ans[b];
      }
    }
    printf("%d\\n", ans[0]);
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  char a[10];
  while (scanf("%s", a) != EOF) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9 - i; j++) {
        a[j] = a[j] + a[j + 1] - '0';
        if (a[j] - '0' > 9)
          a[j] -= 10;
      }
    }
    printf("%c\\n", a[0]);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  char a[10];
  while (scanf("%s", a) != 0) {
    for (int i = 0; i < 9; i++) {
      for (int j = 0; j < 9 - i; j++) {
        a[j] = a[j] + a[j + 1] - '0';
        if (a[j] - '0' > 9)
          a[j] -= 10;
      }
    }
    printf("%c\\n", a[0]);
  }
}
Problem p00062 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  char buf[11];
  while (cin >> buf) {
    for (int i = 0; i < 10; i++)
      buf[i] -= '0';
    for (int i = 9; i > 0; i--) {
      for (int j = 0; j <= i; j++)
        buf[j] = (buf[j] + buf[j + 1]) % 10;
    }
    cout << static_cast<int>(buf[0]) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

bool input(char buf[]) {
  for (int i = 0; i < 10; i++) {
    if (!(cin >> buf[i]))
      return false;
    buf[i] -= '0';
  }
  return true;
}

int main() {
  char buf[10];
  while (input(buf)) {
    for (int i = 9; i > 0; i--) {
      for (int j = 0; j <= i; j++)
        buf[j] = (buf[j] + buf[j + 1]) % 10;
    }
    cout << static_cast<int>(buf[0]) << endl;
  }

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

#include <stdio.h>

int hoge(int x[]) {

  for (int j = 9; j > 0; j--) {
    for (int i = 0; i < j; i++) {
      x[i] = (x[i] + x[i + 1]) % 10;
    }
  }

  return x[0];
}

int main() {
  char a[15];

  while (~scanf("%s", a)) {
    int c[10];
    for (int i = 0; i < 10; i++) {
      c[i] = a[i] - '0';
    }

    c[0] = hoge(c);
    printf("%d\\n", c[0]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int hoge(int x[]) {

  for (int j = 9; j >= 0; j++) {
    for (int i = 0; i < j; i++) {
      x[i] = (x[i] + x[i + 1]) % 10;
    }
  }

  return x[0];
}

int main() {
  char a[15];

  while (~scanf("%s", a)) {
    int c[10];
    for (int i = 0; i < 10; i++) {
      c[i] = a[i] - '0';
    }

    c[0] = hoge(c);
    printf("%d\\n", c[0]);
  }
  return 0;
}
Problem p00062 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string.h>

using namespace std;

int output(int num[10], int len) {
  if (len == 1) {
    return num[0];
  } else {
    int temp[10] = {0};
    len--;
    for (int i = 0; i < len; i++) {
      temp[i] = (num[i] + num[i + 1]) % 10;
    }
    return output(temp, len);
  }
}

int main() {
  string in;
  while (cin >> in) {
    int num[10];
    for (int i = 0; i < 10; i++) {
      num[i] = in[i] - '0';
    }
    cout << output(num, 10) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string.h>

using namespace std;

void output(int num[10], int len) {
  if (len == 1) {
    cout << num[0] << endl;
  } else {
    int temp[10] = {0};
    len--;
    for (int i = 0; i < len; i++) {
      temp[i] = (num[i] + num[i + 1]) % 10;
    }
    output(temp, len);
  }
}

int main() {
  while (1) {
    string in;
    cin >> in;
    int num[10];
    for (int i = 0; i < 10; i++) {
      num[i] = in[i] - '0';
    }
    output(num, 10);
  }
}