alexjercan/bugnet huggingface dataset:
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  for (;;) {
    string a;
    cin >> a;
    int sum = 0;
    if (a[0] == 48)
      break;
    else {
      for (int i = 0; i < (int)a.size(); i++) {
        sum += a[i];
      }
      cout << sum - (48 * (int)a.size()) << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  for (;;) {
    int a, q = 1;
    cin >> a;
    if (a == 0)
      break;
    else {
      int n = 0, k = 1;
      for (;;) {
        if (a / k == 0)
          break;
        else {
          n++;
          k *= 10;
        }
      }
      vector<int> num;
      for (int x = 0; x < n; x++) {
        q *= 10;
        num.push_back((a % q) / (q / 10));
      }
      int sum = 0;
      for (int i = 0; i < (int)num.size(); i++)
        sum += num[i];
      cout << sum << endl;
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) {
    char str[1001];
    int n;
    cin >> str;
    if (str[0] == '0')
      break;
    n = strlen(str);

    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += str[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>

int main() {
  while (1) {
    char str[1001];
    int n;
    scanf("%s", str);
    if (str[0] == 0)
      break;
    n = strlen(str);

    int sum = 0;
    for (int i = 0; i <= n; ++i) {
      sum += str[i] - '0';
    }
    printf("%d", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

void solve8b(string a) {
  int s = 0;
  REP(i, a.size()) { s += a[i] - '0'; }
  cout << s << endl;
}

int main() {
  string a;
  while (cin >> a) {
    if (a == "0")
      break;
    solve8b(a);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

void solve8b(long long a) {
  int s = 0;
  while (a) {
    s += a % 10;
    a /= 10;
  }
  cout << s << endl;
}

int main() {
  long long a;
  while (cin >> a, a) {
    solve8b(a);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <string>

using namespace std;

int main() {
  string l;
  while (getline(cin, l)) {
    if (l == "0") {
      break;
    }

    int s = 0;
    for (size_t i = 0; i < l.size(); ++i) {
      const char c = l[i];
      s += atoi(&c);
    }
    printf("%d\\n", s);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int x;
  for (;;) {
    cin >> x;
    if (x == 0) {
      break;
    }
    int s = 0;
    for (int n = x; n > 0; n /= 10) {
      s += n % 10;
    }
    printf("%d\\n", s);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int sum;
  char ch[10000];
  while (1) {
    scanf("%s", ch);
    if (ch[0] == '0')
      break;
    sum = 0;
    for (int i = 0; i < strlen(ch); i++) {
      sum = sum + (ch[i] - '0');
    }
    printf("%d\\n", sum);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int sum;
  char ch[100];
  while (1) {
    scanf("%s", ch);
    if (ch[0] == '0')
      break;
    sum = 0;
    for (int i = 0; i < strlen(ch); i++) {
      sum = sum + (ch[i] - '0');
    }
    printf("%d\\n", sum);
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

// ??°???input????????????string??¨??????????´??????????????????¨
// ???????????????????????\\???char??¨????????????????????????c - '0'??§int???

int main() {
  vector<string> v;
  string temp;
  int n;
  long sum = 0;
  while (1) {
    cin >> temp;
    if (temp == "0")
      break;
    v.push_back(temp);
  }

  for (auto str : v) {
    temp = str;
    for (char &c : str) {
      n = c - '0';
      sum += n;
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int temp;
  long sum = 0;
  vector<int> v;
  while (1) {
    cin >> temp;
    if (temp == 0)
      break;
    v.push_back(temp);
  }

  for (auto i : v) {
    temp = i;
    while (1) {
      if (temp == 0)
        break;
      sum += (temp % 10);
      temp /= 10;
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  char x[1001];

  while (1) {
    int sum = 0;
    cin >> x;
    if (x[0] == '0')
      break; // 条件文で比較するときは''をつけること‼‼

    for (int i = 0; x[i] != '\\0'; i++) {
      sum += x[i] - '0';
    }
    cout << sum << endl;
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {  // x=0のとき終わり
  char x[10]; // 文字列を作成

  while (1) {
    int sum = 0;
    scanf("%s", x);
    // if(x == "0") break; //x=0のとき終わり

    for (int i = 0; x[i] != '\\0';
         i++) { // 文字列に入力されたやつの末端まで読み込む 末端文字は\\0と表す
      // printf("%d",x[i]," ");
      sum += x[i];
    }
    if (sum == 0)
      break;
    printf("%d", sum);
    printf("\\n");
    // break;
  }

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

#include <cstdio>
#include <iostream>
int main() {
  int i = 0, a, num = 0, sum[1000] = {0};
  char x[1000];
  while (1) {
    for (i = 0;; i++) {
      scanf("%c", &x[i]);
      if (x[i] == '\\n')
        break;
      sum[num] += x[i] - '0';
    }
    if (x[0] == '0' && x[1] == '\\n')
      break;
    num++;
  }
  for (i = 0; i < num; i++) {
    std::cout << sum[i] << std::endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
int main() {
  int i = 0, a, num, b = 1, sum, x[1000];
  while (1) {
    std::cin >> b;
    if (b == 0)
      break;
    x[i] = b;
    i++;
  }
  num = i;
  for (i = 0; i < num; i++) {
    a = x[i];
    for (sum = 0; a > 0;) {
      sum += a % 10;
      a = a / 10;
    }
    std::cout << sum << std::endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string num;
  cin >> num;
  while (num[0] != '0') {
    int i, sum = 0;
    for (i = 0; i < num.size(); i++) {
      sum += num[i] - '0';
    }
    cout << sum << endl;
    cin >> num;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int i, j, k;
  char name[1000];
  while (1) {
    cin >> name;

    if (name[0] == 0)
      break;
    for (j = 0; j < 1000; j++) {
      i = name[j] - '0';
      k += i;
    }
    cout << k << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  char s[1001] = {0};
  int sum = 0;
  while (1) {
    cin >> s;
    if (strcmp(&s[0], "0") == 0) {
      break;
    }
    for (int i = 0; s[i] != '\\0'; i++) {
      sum += (int)(s[i] - '0');
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  char s;
  int sum = 0;
  while (1) {
    scanf("%c", &s);
    sum += atoi(&s);
    if (sum == 0) {
      break;
    }
    while (1) {
      scanf("%c", &s);
      if (s == '\\n') {
        cout << sum << endl;
        break;
      }
      sum += atoi(&s);
    }
  }
  sum = 0;
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <sstream>
using namespace std;
int main() {
  while (1) {

    char num[1002];
    cin >> num;
    // cout << num[0] << endl;
    if (num[0] == '0') {
      break;
    } else {
      int sums = 0;
      for (int i = 0; num[i] != '\\0'; i++) {
        int one_num;
        one_num = num[i] - '0';
        sums += one_num;
      }
      cout << sums << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  int ans[50000];
  int count;
  while (1) {
    string number;
    cin >> number;
    int one_sum = 0;
    for (int i = 0; i < number.size(); i++) {
      int a = number[i] - '0';
      one_sum += a;
    }
    ans[count] = one_sum;
    count += 1;
    if (one_sum == 0) {
      break;
    }
  }
  int word = 0;

  while (word < count - 1) {
    cout << ans[word] << '\\n';
    word += 1;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  string s;
  while (true) {
    cin >> s;
    if (s[0] == '0')
      break;
    else {
      int ans = 0;
      for (int i = 0; i < s.size(); i++) {
        ans += s[i] - '0';
      }
      cout << ans << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int x;
  while (true) {
    cin >> x;
    if (x == 0)
      break;
    int tmp = x;
    int sum = 0;
    while (tmp > 0) {
      sum += tmp % 10;
      tmp /= 10;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  string num;
  int sum = 0;
  while (1) {
    cin >> num;
    if (num == "0") {
      break;
    }
    for (int i = 0; i < (int)num.size(); i++) {
      sum = sum + (int)num[i] - 48;
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char ch;
  int sum = 0;
  while (ch == 0) {
    sum += (ch - '0');
    if (ch == '\\n') {
      cout << sum << endl;
      sum = 0;
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char x[1000];
  unsigned int i, a = 0;

  while (1) {
    scanf("%s", x);
    if (strcmp(x, "0") == 0)
      break;

    a = 0;
    for (i = 0; i < strlen(x); ++i) {
      if (x[i] != '0') {
        x[i] -= '0';
        a += x[i];
      }
    }
    printf("%d", a);
    printf("\\n");
  }

  return 0;
}


Error: -11

Fixed submission:


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

int main() {
  char *x;
  int i, a = 0;

  while (1) {
    scanf("%s", x);
    if (strcmp(x, "0") == 0)
      break;

    a = 0;
    for (i = 0; i < strlen(x); ++i) {
      if (x[i] != '0') {
        x[i] -= '0';
        a += x[i];
      }
    }
    printf("%d", a);
    printf("\\n");
  }

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

#include <stdio.h>

int main(void) {
  int i;

  while (1) {
    char x[1001];
    int sum = 0;
    int re; //??°?????????????????´

    scanf("%s", x);

    if ((x[0] == '0') && (x[1] == '\\0')) //??????0????????????
      break;

    for (i = 0; (!(x[i])) == '\\0'; i++) { //??????????????????????????§?????????
      re = x[i] - '0';                    //??°?????¨?????????????????????
      sum = sum + re;                     //????¨?????????????
    }

    printf("%d\\n", sum);
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int i;

  while (1) {
    char x[1001];
    int sum = 0;
    int re; //??°?????????????????´

    scanf("%[^\\n]", x); //?????????????????§????????????

    if ((x[0] == '0') && (x[1] == '\\0')) //??????0????????????
      break;

    for (i = 0; (!(x[i])) == '\\0'; i++) { //??????????????????????????§?????????
      re = x[i] - '0';                    //??°?????¨?????????????????????
      sum = sum + re;                     //????¨?????????????
    }

    printf("%d\\n", sum);
  }

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

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int count, count2 = 0, ans[1000] = {0};
  char number[1000];
  while (1) {
    scanf("%s", &number);
    for (count = 0; number[count] != '\\0'; count++) {
      ans[count2] += (number[count] - '0');
    }
    if (ans[count2] == 0) {
      break;
    }
    count2++;
  }
  for (count = 0; count < count2; count++) {
    cout << ans[count] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int count, count2 = 0, ans[100] = {0};
  char number[1000];
  while (1) {
    scanf("%s", &number);
    for (count = 0; number[count] != '\\0'; count++) {
      ans[count2] += (number[count] - '0');
    }
    if (ans[count2] == 0) {
      break;
    }
    count2++;
  }
  for (count = 0; count < count2; count++) {
    cout << ans[count] << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int result = 0;
    char c;
    while (true) {
      scanf("%c", &c);
      if (result == 0 && c == '0') {
        break;
      }
      if (c == '\\n') {
        break;
      }
      result += c - 0x30;
    }
    if (result == 0 && c == '0') {
      break;
    }
    std::cout << result << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int sum(int x);

int main() {
  while (true) {
    int x;
    std::cin >> x;
    if (x == 0) {
      break;
    }
    std::cout << sum(x) << std::endl;
  }
  return 0;
}

int sum(int x) {
  int result = 0;
  while (x != 0) {
    result += x % 10;
    x /= 10;
  }
  return result;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    int s = 0, d = 0;
    char a[1000];
    cin >> a;
    if (a[0] == 48)
      break;
    for (int i = 0; i < strlen(a); i++) {
      s += a[i];
      d++;
    }
    cout << s - d * 48 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    int s = 0, d = 0;
    char a[5];
    cin >> a;
    if (a[0] == 48)
      break;
    for (int i = 0; i < strlen(a); i++) {
      s += a[i];
      d++;
    }
    cout << s - d * 48 << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  std::string str;

  while (std::cin >> str) {
    if (str == "0")
      break;
    int sum = 0;
    for (int i = 0; str[i] != '\\0'; ++i) {
      sum += str[i] - '0';
    }
    std::cout << sum << std::endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  std::string str;

  while (1) {
    std::cin >> str;
    int sum = 0;
    for (int i = 0; str[i] != '\\0'; ++i) {
      char c = str[i];
      sum += std::atoi(&c);
    }
    if (sum == 0)
      break;
    std::cout << sum << std::endl;
  }

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

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

int main() {
  char c[1000][1001];
  int a;

  for (int i = 0; i < 1000; i++) {
    scanf("%s", c[i]);
    // if (c[i][0] == '0' && c[i][1] == NULL) {
    if (strcmp(c[i], "0") == 0) {
      a = i;
      break;
    }
  }
  for (int i = 0; i <= a; i++) {
    int sum = 0;
    for (int j = 0; j < 1000; j++) {
      if (c[i][j] == '\\0')
        break;
      sum += c[i][j] - 48;
    }
    if (sum != 0)
      cout << sum << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  char c[10000][1001];
  int a;

  for (int i = 0; i < 10000; i++) {
    scanf("%s", c[i]);
    // if (c[i][0] == '0' && c[i][1] == NULL) {
    if (strcmp(c[i], "0") == 0) {
      a = i;
      break;
    }
  }
  for (int i = 0; i <= a; i++) {
    int sum = 0;
    for (int j = 0; j < 1000; j++) {
      if (c[i][j] == '\\0')
        break;
      sum += c[i][j] - 48;
    }
    if (sum != 0)
      cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  char charr[1001] = {};
  int result;

  while (1) {
    scanf("%s", charr);
    if (charr[0] == '0') {
      break;
    }

    result = 0;
    for (int i = 0; charr[i] != '\\0'; i++) {
      result += charr[i] - '0';
    }
    printf("%d\\n", result);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int num, result;
  string number;

  while (1) {
    cin >> number;

    for (int i = 0;; i++) {
      num = number[i] - '0';
      if (num == 0) {
        break;
      }
      result += num;
    }
    cout << endl;
  }
  cout << endl;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int main() {
  int i, s;
  char d[1001];
  while (i = 0, s = 0, std::cin >> d) {
    while (d[i] - '\\0') {
      s += d[i] - '0';
      ++i;
    }
    if (s == 0)
      break;
    std::cout << s << std::endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  int i, s;
  char d[1001];
  while (i = 0, s = 0, std::cin >> d, d) {
    while (d[i] - '\\0') {
      s += d[i] - '0';
      ++i;
    }
    std::cout << s << std::endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int ctoi(char);

int main() {
  string s;
  // char strs;

  while (1) {
    cin >> s;
    if (s == "0")
      break;
    int digs = 0;
    for (long unsigned int i = 0; i < s.length(); i++) {
      // char strs = s[i];
      digs += ctoi(s[i]);
    }
    cout << digs << endl;
  }
  return 0;
}

int ctoi(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return 0;
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n;

  while (1) {
    cin >> n;
    if (n == 0)
      break;

    cout << n % 10 + (n / 10) % 10 + (n / 100) % 10 + (n / 1000) % 10 << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

/*ITP1_8_B
#include<iostream>
using namespace std;

int main()
{
        int x,a;
        for(;;){
                cin>>x;
                if(x==0)
                        break;
                for(a=0;x!=0;x/=10){
                        a+=x%10;
                        }
                cout<<a<<endl;
        }
        return 0;
}
*/

#include <iostream>
#include <string>

using namespace std;

int main() {
  string ch;
  int ans = 0;

  while (1) {
    cin >> ch;
    if (ch == "0")
      break;

    for (int i = 0; i < ch.size(); i++) {
      ans += ch[i] - '0';
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

// ITP1_8_B
#include <iostream>
using namespace std;

int main() {
  int x, n, a;
  for (;;) {
    cin >> x;
    if (x == 0)
      break;
    for (; x != 0 && (x % 10) % 2 == 0;)
      a += x % 10;
    x = x / 10;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char str[1001];

  while (1) {
    scanf("%s", str);
    if (str[0] == '0')
      break;

    int sum = 0;
    for (int i = 0; i < strlen(str); i++) {
      sum += str[i] - '0';
    }

    printf("%d\\n", sum);
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  char str[1001];

  while (1) {
    scanf("%s", str);
    if (str[0] = 0)
      break;

    int sum = 0;
    for (int i = 0; i <= strlen(str); i++) {
      sum += str[i] - '0';
    }

    printf("%d\\n", sum);
  }

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

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

int main() {
  char x[1000];

  while (1) {
    scanf("%s", x);
    if (x[0] == '0')
      break;
    int sum = 0;
    for (int i = 0; i < strlen(x); i++) {
      sum += (x[i] - '0');
    }

    printf("%d\\n", sum);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  char x[1000];

  while (1) {
    scanf("%s", x);
    if (x[0] == 0)
      break;
    int sum = 0;
    for (int i = 0; i < strlen(x); i++) {
      sum += (x[i] - '0');
    }

    printf("%d\\n", sum);
  }

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

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

int main() {
  string number;
  int sum;
  while (1) {
    sum = 0;

    // while(1){
    cin >> number;
    // scanf("%s",&number);
    // if(number == '\\n')break;
    // }

    if (number[0] == '0' && number.size() == 1)
      break;

    for (int i = 0; i < number.size(); i++) {
      sum += number[i] - '0';
      number[i] = '0';
    }
    cout << sum << endl;
  }
  return 0;
}


Error: -11

Fixed submission:

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

int main() {
  string number;
  int sum;
  while (1) {
    sum = 0;

    // while(1){
    // cin >> number;
    scanf("%s", &number);
    // if(number == '\\n')break;
    // }

    if (number[0] == '0' && number.size() == 1)
      break;

    for (int i = 0; i < number.size(); i++) {
      sum += number[i] - '0';
      number[i] = '0';
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  char num[1000][1010];
  int jump;
  int outnum[100] = {};

  for (int i = 1; i <= 2000; i++) {
    cin >> num[i];
    if (num[i][0] == '0') {
      jump = i;
      break;
    }
  }
  for (int t = 1; t < jump; t++) {
    for (int u = 0; u <= 2000; u++) {
      if (num[t][u] == '\\0') {
        cout << outnum[t] << "\\n";
        break;
      }
      outnum[t] += num[t][u] - 48;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  char num[100][1000];
  int jump;
  int outnum[100] = {};

  for (int i = 1; i <= 10000; i++) {
    cin >> num[i];
    if (num[i][0] == '0') {
      jump = i;
      break;
    }
  }
  for (int t = 1; t < jump; t++) {
    for (int u = 0; u <= 1000; u++) {
      if (num[t][u] == '\\0') {
        cout << outnum[t] << "\\n";
        break;
      }
      outnum[t] += num[t][u] - 48;
    }
  }
  return 0;
}