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

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

int main() {
  char x[1001];
  int i, sum = 0;
  while (scanf("%s\\n", x)) {
    sum = 0;
    if (x[0] == '0')
      break;
    for (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() {
  char x[1001];
  int i, sum;
  while (1) {
    i = 0;
    scanf("%s", x);
    while (x[i] - '0') {
      sum += x[i];
      i++;
    }
    if (sum == 0)
      break;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  char x[1000][1001] = {"a"};
  int check;
  int a[1000] = {};
  for (int i = 0; i < 1000; i++) {
    cin >> x[i];
    if (x[i][0] == '0') {
      break;
    }
    for (int i2 = 0; i2 < 1001; i2++) {
      if (x[i][i2] != '\\0' && x[i][i2] != 'a') {
        a[i] += x[i][i2] - '0';
      }
    }
    check = i;
  }
  for (int i = 0; i <= check; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  char x[100][1001] = {"a"};
  long long int check;
  int a[100] = {};
  for (int i = 0; i < 1000; i++) {
    cin >> x[i];
    if (x[i][0] == '0') {
      break;
    }
    for (int i2 = 0; i2 < 1001; i2++) {
      if (x[i][i2] != '\\0' && x[i][i2] != 'a') {
        a[i] += x[i][i2] - '0';
      }
    }
    check = i;
  }
  for (int i = 0; i <= check; i++) {
    cout << a[i] << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  while (true) {
    int i, S = 0;
    char x[1000] = {0};
    cin >> x;
    for (i = 0; i < 1000; i++) {
      if (x[i] == '\\n') {
        break;
      }
      switch (x[i]) {
      case '0':
        S = S + 0;
        break;
      case '1':
        S = S + 1;
        break;
      case '2':
        S = S + 2;
        break;
      case '3':
        S = S + 3;
        break;
      case '4':
        S = S + 4;
        break;
      case '5':
        S = S + 5;
        break;
      case '6':
        S = S + 6;
        break;
      case '7':
        S = S + 7;
        break;
      case '8':
        S = S + 8;
        break;
      case '9':
        S = S + 9;
        break;
      }
    }
    if (S == 0) {
      break;
    }
    cout << S << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char x[1000] = {0};
  int i, S = 0;
  while (true) {
    cin >> x;
    for (i = 0; i < 1000; i++) {
      if (x[i] == '\\n') {
        break;
      }
      switch (x[i]) {
      case '0':
        S = S + 0;
        break;
      case '1':
        S = S + 1;
        break;
      case '2':
        S = S + 2;
        break;
      case '3':
        S = S + 3;
        break;
      case '4':
        S = S + 4;
        break;
      case '5':
        S = S + 5;
        break;
      case '6':
        S = S + 6;
        break;
      case '7':
        S = S + 7;
        break;
      case '8':
        S = S + 8;
        break;
      case '9':
        S = S + 9;
        break;
      }
    }
    if (S == 0) {
      break;
    }
    cout << S << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char ch[1000];

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

    for (int i = 0; i < strlen(ch); i++) {
      sum += ch[i] - '0';
    }
    printf("%d\\n", sum);
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  char ch[1000] = {};
  int i = 0;
  int sum = 0;
  scanf("%c", ch[i]);
  while (1) {

    if (ch[i] == 0 && ch[i - 1] == '\\n') {
      break;
    } else if (ch[i] == '\\n') {
      printf("%c\\n", sum);
      sum = 0;
    } else {
      sum += ch[i];
    }
    i += 1;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char ch[1000] = "A";
  int num, i, a;
  while (true) {
    scanf("%s", &ch);
    if (ch[0] == '0')
      break;
    i = 0;
    num = 0;
    while (true) {
      if (ch[i] == '\\0')
        break;
      a = ch[i] - '0';
      num += a;
      a = 0;
      i += 1;
    }
    cout << num << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  char ch[1000] = "A";
  int num, i, a;
  while (true) {
    scanf("%s", &ch);
    if (ch == "0")
      break;
    i = 0;
    num = 0;
    while (true) {
      if (ch[i] == '\\n')
        break;
      a = ch[i] - '0';
      num += a;
      a = 0;
      i += 1;
    }
    cout << num << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  char x[1001];
  while (1) {
    int U = 0, i = 0;

    scanf("%s", x);
    if (x[0] == '0')
      break;

    while (x[i] != '\\0') {
      U += x[i] - '0';
      ++i;
    }

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

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  char x[1001];
  while (1) {
    int U = 0, i = 0;
    scanf("%s", x);
    if (x[0] == 0)
      break;
    while (x[i] != '\\0') {
      U += x[i] - '0';
      ++i;
    }
    printf("%d\\n", U);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {

  int d;
  string num;

  for (int i = 0;; i++) {
    getline(cin, num);
    if (num[0] == '0')
      break;
    d = 0;
    for (int j = 0; j < num.length(); j++) {
      d += num[j] - '0';
    }
    cout << d << "\\n";
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {

  int d;
  string num;

  for (int i = 0;; i++) {
    getline(cin, num);
    if (num[i] == '0')
      break;
    d = 0;
    for (int j = 0; j < num.length(); j++) {
      d += num[j] - '0';
    }
    cout << d << "\\n";
  }

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

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

using namespace std;

int main() {
  char str[1001];

  while (true) {
    cin >> 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: 0

Fixed submission:

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

using namespace std;

int main() {
  char str[100];

  while (true) {
    cin >> 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 <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {

  for (string s; cin >> s && s != "0";) {
    int a = 0;
    for (int i = 0; i < s.size(); i++) {
      a += s[i] - '0';
    }
    cout << a << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int sum;
  while (1) {
    sum = 0;
    for (char c; c = getchar(); c != '\\0') {
      sum += c - 48;
    }
    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int s, l, k, j, i;
  string n, m[1001] = {};
  k = 0;
  do {
    k = k + 1;
    cin >> n;
    m[k] = n;
  } while (n != "0");

  j = k - 1;
  for (k = 1; k <= j; k++) {
    i = m[k].size();
    s = 0;
    for (l = 0; l <= i - 1; l++)
      s = s + (m[k][l] - '0');
    cout << s << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  int s, l, k, j, i;
  string n, m[100] = {};
  k = 0;
  do {
    k = k + 1;
    cin >> n;
    m[k] = n;
  } while (n != "0");

  j = k - 1;
  for (k = 1; k <= j; k++) {
    i = m[k].size();
    s = 0;
    for (l = 0; l <= i - 1; l++)
      s = s + (m[k][l] - '0');
    cout << s << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

using namespace std;

int main() {
  char ch[1001];

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

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

using namespace std;

int main() {
  char ch[1001];

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

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

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

#include <cstdio>

int main() {
  char s[1201];
  int c;
  while (1) {
    scanf("%s", s);
    c = 0;
    if (s[0] == '0') {
      break;
    }
    for (int i = 0; s[i] != '\\0'; i++) {
      c += s[i] - 48;
    }
    printf("%d\\n", c);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  char s[1201];
  int c;
  while (1) {
    scanf("%[^\\n]", s);
    c = 0;
    if (s[0] == '0') {
      break;
    }
    for (int i = 0; s[i] != '\\0'; i++) {
      c += s[i] - 48;
    }
    printf("%d\\n", c);
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char x[1001];
  int num;
  bool f = 0;
  while (1) {
    scanf("%s", x);
    if (x[0] == '0')
      break;
    int sum = 0;
    for (int i = 0; i < strlen(x); i++) {
      num = x[i] - '0';
      sum += num;
    }
    printf("%d\\n", sum);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  char x[1001];
  int num;
  bool f = 0;
  while (1) {
    scanf("%s", x);
    if (x[0] == 0)
      break;
    int sum = 0;
    for (int i = 0; i < strlen(x); i++) {
      num = x[i] - '0';
      sum += num;
    }
    printf("%d\\n", sum);
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

int sumNum(string n) {
  int sum = 0;
  for (int i = 0; i <= n.size(); i++) {
    sum += atoi(n.substr(i, 1).c_str());
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int i = 0;
  while (true) {
    string n;
    cin >> n;
    if (n == "0") {
      break;
    }
    cout << sumNum(n) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int sumNum(int no) { return no == 0 ? 0 : no % 10 + sumNum(no / 10); }

const int maxn = 10000;

int ans[maxn];

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int i = 0;
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    ans[i] = sumNum(n);
    i++;
  }
  for (int j = 0; j < i; j++) {
    cout << ans[j] << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string x;
  while (true) {
    int answer;
    answer = 0;
    cin >> x;
    if (x[0] == '0')
      break;
    for (int i = 0; i < x.size(); i++) {
      answer += x[i] - '0';
    }
    cout << answer << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string x;
  while (true) {
    int answer;
    answer = 0;
    cin >> x;
    for (int i = 0; i < x.size(); i++) {
      answer += x[i] - '0';
    }
    cout << answer << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "iostream"
#include "string"
using namespace std;

int main(int argc, char const *argv[]) {
  char x[1001];
  int y[1001];
  int sum = 0;
  int count = 0;
  int i = 0;

  while (true) {
    sum = 0;
    i = 0;
    cin >> x;
    // if(strncmp(x, "0", 1001) == 0)
    // {
    // 	break;
    // }

    if (x[0] == 48) {
      break;
    }

    while (x[i] != 0) {
      sum += x[i] - '0';
      i++;
    }

    cout << sum << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int x = 0;
  int ans;

  while (true) {
    ans = 0;
    cin >> x;

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

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char inputInt[2000];
  while (true) {
    cin.getline(inputInt, 2000);
    int length = strlen(inputInt);
    int sum = 0;
    if (length == 1 && inputInt[0] == '0')
      break;
    for (int i = 0; i < length; i++) {
      sum += inputInt[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char inputInt[1000];
  while (true) {
    cin.getline(inputInt, 1000);
    int length = strlen(inputInt);
    int sum = 0;
    if (length == 1 && inputInt[0] == '0')
      break;
    for (int i = 0; i < length; i++) {
      sum += inputInt[i] - '0';
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
int main() {
  char str[1001];
  int sum;

  for (;;) {
    sum = 0;
    scanf("%s", str);
    for (int i = 0; i < strlen(str); i++) {
      sum += str[i] - '0';
    }
    if (str[0] - '0' == 0)
      break;
    printf("%d\\n", sum);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  char x;
  int sum;

  for (;;) {
    sum = 0;
    for (;;) {
      scanf("%c", &x);
      if (x == '\\n')
        break;
      sum += x - '0';
    }
    if (x - '0' == 0)
      break;
    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 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);
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char str[1001];
  while (1) {
    scanf("%s", str);
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

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: -11

Fixed submission:

#include <cstdio>
#include <cstring>

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 <iostream>
#include <string>
using namespace std;

int main(void) {
  string num;

  while (true) {
    cin >> num;

    if (num[0] == '0')
      break;
    int sum = 0;

    for (int i = 0; i < num.size(); i++) {
      sum += num[i] - '0';
    }

    cout << sum << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  string num;
  int sum;

  while (true) {
    cin >> num;

    if (num[0] == 0)
      break;
    sum = 0;

    for (int i = 0; i < num.size(); i++) {
      sum += num[i];
    }

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

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

int main() {
  string number;
  int sum, num;
  string::size_type size;

  while (1) {
    cin >> number;
    if (number == "0")
      break;
    size = number.size();
    sum = 0;

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

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, sum;

  while (1) {
    cin >> a;
    if (a == 0)
      return 0;
    sum = 0;
    for (; a >= 10; a /= 10) {
      sum += a % 10;
    }
    sum += a;
    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  char number[1001];
  int i, sum;
  while (1) {
    scanf("%s", number);
    if (number[0] == '0')
      break;
    sum = 0;
    for (i = 0; number[i] != '\\0'; i++) {
      sum += number[i] - '0';
    }
    printf("%d\\n", sum);
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int keta(long long int n) {
  int count = 0;
  while (n != 0) {
    n = n / 10;
    count += 1;
  }
  return count;
}

int main() {
  int k;
  int i = 0;
  long long int a[10000][2];
  while (1) {
    cin >> a[i][0];
    if (a[i][0] == 0) {
      break;
    }
    a[i][1] = keta(a[i][0]);
    i++;
  }

  for (int n = 0; n < i; n++) {
    int sum = 0;
    int ten = 1;
    while (a[n][0] != 0) {
      sum += a[n][0] % (ten * 10) / ten;
      a[n][0] -= a[n][0] % (ten * 10);
      ten *= 10;
    }
    cout << sum << endl;
  }
}
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++) {
      int a = str[i] - '0';
      sum += a;
    }
    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++) {
      int a = str[i] - '0';
      sum += a;
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int num = 0;
  char fig[1001];

  while (1) {
    scanf("%s", fig);
    if (fig == "0")
      break;
    for (int i = 0; fig[i] != '\\0'; i++) {
      num += fig[i] - '0';
    }
    if (num == 0)
      break;
    printf("%d\\n", num);
    num = 0;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {

  int num = 0;
  char fig[5];

  while (1) {
    scanf("%s", fig);
    if (fig == "0")
      break;
    for (int i = 0; fig[i] != '\\0'; i++) {
      num += fig[i] - '0';
    }
    if (num == 0)
      break;
    printf("%d\\n", num);
    num = 0;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  char str[1001] = {0};

  cin.getline(str, 1001);

  while (str[0] != '0') {
    int n = 0;

    for (unsigned int i = 0; i < strlen(str); i++)
      n += str[i] - '0';

    cout << n << endl;

    cin.getline(str, 1001);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  char str[1001] = {0};

  cin.getline(str, 1000);

  while (str[0] != '0') {
    int n = 0;

    for (unsigned int i = 0; i < strlen(str); i++)
      n += str[i] - '0';

    cout << n << endl;

    cin.getline(str, 1000);
  }

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

#include <stdio.h>
int main() {
  char moji[1001];
  int sum, cou, tn;
  while (1) {
    scanf("%s", moji);
    if (moji[0] == '0') {
      break;
    }
    sum = 0;
    cou = 0;
    while (1) {
      if (moji[cou] == '\\0') {
        break;
      }
      tn = moji[cou] - '0';
      sum = sum + tn;
      cou = cou + 1;
    }
    printf("%d\\n", sum);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  char moji[1001];
  int sum, cou, tn;
  while (1) {
    scanf("%s", moji);
    if (moji[0] = '\\0') {
      break;
    }
    sum = 0;
    cou = 0;
    while (1) {
      if (moji[cou] == '\\0') {
        break;
      }
      tn = moji[cou] - '0';
      sum = sum + tn;
      cou = cou + 1;
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  while (true) {
    int X;
    cin >> X;
    if (X == 0) {
      break;
    }
    int sum = 0;
    int dig;
    while (X) {
      dig = X / 10;
      sum = sum + dig;
      X = X % 10;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>

int main() {
  char number[1000];
  while (1) {
    scanf("%s", number);
    if (number[0] == '0')
      break;
    int sum = 0;
    for (int i = 0; i < strlen(number); i++) {
      sum += (number[i] - '0');
    }
    printf("%d\\n", sum);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

int main() {
  char number[1000];
  while (1) {
    scanf("%s", number);
    if (number[0] == 0)
      break;
    int sum = 0;
    for (int i = 0; i < strlen(number); i++) {
      sum += (number[i] - '0');
    }
    printf("%d\\n", sum);
  }

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

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

int main() {
  string a, b;
  int i, c;
  while (1) {
    cin >> a;
    if (a == "0") {
      break;
    }
    c = 0;
    for (i = 0; i < a.size(); i++) {
      b = a.substr(i, 1);
      if (b == "1") {
        c += 1;
      }
      if (b == "2") {
        c += 2;
      }
      if (b == "3") {
        c += 3;
      }
      if (b == "4") {
        c += 4;
      }
      if (b == "5") {
        c += 5;
      }
      if (b == "6") {
        c += 6;
      }
      if (b == "7") {
        c += 7;
      }
      if (b == "8") {
        c += 8;
      }
      if (b == "9") {
        c += 9;
      }
    }
    cout << c << endl;
  }
  return 0;
}

Error: -8

Fixed submission:

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

int main() {
  int a, b, i;
  while (1) {
    b = 0;
    cin >> a;
    if (a == 0) {
      break;
    }
    for (i = 1; i <= 1000; i++) {
      b += a / (10 ^ (i - 1)) % 10;
      cout << b << endl;
    }
  }
  return 0;
}