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

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

int calcSumOfNumbers(const char x[]);

int main(void) {
  while (1) {
    char x[1000] = "\\0";
    cin >> x;

    if (x[0] == '0')
      break;

    cout << calcSumOfNumbers(x) << endl;
  }

  return 0;
}

int calcSumOfNumbers(const char x[]) {
  int sum = 0;
  for (int i = 0; x[i] != '\\0'; i++) {
    sum += x[i] - '0';
  }

  return sum;
}

Error: TLE

Fixed submission:

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

inline int calcSumOfNumbers(int x);

int main(void) {
  while (1) {
    int x;
    cin >> x;

    if (x == 0)
      break;

    cout << calcSumOfNumbers(x) << endl;
  }

  return 0;
}

inline int calcSumOfNumbers(int x) {
  int sum = 0;
  do {
    sum += x % 10;
    x /= 10;
  } while (x);

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

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

int main(void) {
  char x[1000] = "";
  int sum;

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

  } while (true);

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  char x[1000] = "";
  int sum;

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

  } while (x != "0");

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

#include <iostream>
#include <string>
using namespace std;
int main() {
  int answer;
  string str;

  while (1) {
    answer = 0;
    cin >> str;
    for (int i = 0; i < str.size(); i++) {
      answer += str[i] - '0';
    }

    if (answer == 0)
      break;

    cout << answer << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int answer = 0;
  string str;
  cin >> str;
  while (1) {
    for (int i = 0; i < str.size(); i++) {
      answer += str[i] - '0';
    }

    if (answer == 0)
      break;

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

#include <algorithm>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string input;
  int sum;
  for (;;) {
    cin >> input;
    if (input == "0")
      return 0;

    sum = 0;

    for (auto a : input) {
      if (a == '0')
        continue;
      sum += a - 48;
    }

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

Error: 0

Fixed submission:


#include <algorithm>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string input;
  int sum;
  for (;;) {
    cin >> input;
    if (stoi(input) == 0)
      return 0;

    sum = 0;

    for (auto a : input) {
      if (a == '0')
        continue;
      sum += a - 48;
    }

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

#include <stdio.h>
int main() {
  int i;
  while (1) {
    char str[1000];
    int s = 0;
    scanf("%s\\n", str);
    if (str[0] == '0')
      break;
    for (i = 0; str[i] != '\\0'; i++) {
      s += str[i] - '0';
    }
    printf("%d\\n", s);
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  string s;
  while (1) {
    cin >> s;
    if (s == "0")
      break;
    int sum = 0;
    for (char c : s)
      sum += c - '0';
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

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


Error: TLE

Fixed submission:

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

#include <cstdio>
#include <cstring>

using namespace std;

int main() {
  while (true) {
    int sum = 0;
    char number[1001];
    scanf("%s", number);
    if (strcmp(number, "0") == 0)
      break;

    int i = 0;
    while (number[i]) {
      sum += number[i] - '0';
      i++;
    }
    printf("%d\\n", sum);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

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

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

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

int main(void) {

  string num;
  while (true) {
    cin >> num;
    if (num == "0") {
      break;
    }

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

    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {

  int x;
  while (true) {
    cin >> x;
    if (x == 0)
      break;

    int sum = 0;
    while (true) {
      if (x / 10 == 0) {
        sum += x;
        break;
      }
      sum += x % 10;
      x /= 10;
    }

    cout << sum << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  char c;
  int v;

  while (true) {
    v = 0;

    while (true) {
      cin.get(c);
      if (!isdigit(c))
        break;

      v += c - '0';
    }

    if (0 == v)
      break;

    cout << v << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, t = 0, r, s;

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

    t = 0;
    r = n;

    do {
      s = r % 10;
      r = r / 10;
      t += s;
    } while (r != 0);

    cout << t << "\\n";
  }

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

#include <cctype>
#include <stdio.h>

int main() {
  char ch;
  int sum = 0;
  while (true) {
    while ((ch = getchar()) != '\\n') {
      sum += ch - '0';
    }
    if (sum == 0) {
      break;
    } else {
      printf("%d\\n", sum);
      sum = 0;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cctype>
#include <stdio.h>

int main() {
  char ch;
  int sum = 0;
  while (true) {
    while (ch = getchar() != '\\n') {
      sum += ch - '0';
    }
    if (sum == 0) {
      break;
    } else {
      printf("%d", sum);
      sum = 0;
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()

int main() {
  while (1) {
    char buf[1100];
    scanf("%s", buf);
    if (buf[0] == '0')
      break;
    ll int ans = 0;
    for (int i = 0; buf[i] != '\\0'; i++) {
      ans += buf[i] - '0';
    }
    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()

int main() {
  while (1) {
    int n;
    cin >> n;
    int ans = 0;
    while (n >= 1) {
      ans += n % 10;
      n /= 10;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char name[1001];
  int a = 0;
  int sum = 0;
  while (1) {
    scanf("%s", name);
    if (name[0] == '0')
      break;
    else {
      while (name[a] != '\\0') {
        sum = sum + name[a] - 48;
        a += 1;
      }
      printf("%d\\n", sum);
      a = 0;
      sum = 0;
    }
  }
}


Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char n[1001];
  int sum = 0;
  int a = 0;
  while (1) {
    scanf("%c", &n[a]);
    if (n[0] == 0)
      break;
    else if (n[a] == '\\n') {
      printf("%d", sum);
      sum = 0;
      a = 0;
    } else {
      sum = sum + 'n';
      a += 1;
    }
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int sum_each_digit() {
  char x[1001];
  int ans = 0;
  std::cin >> x;
  if (x[0] == '0')
    return -1;
  for (int i = 0; x[i] != '\\0'; i++) {
    ans += (int)x[i] - 48;
  }
  return ans;
}

int main() {
  int ans;
  while (true) {
    ans = sum_each_digit();
    if (ans == -1)
      break;
    std::cout << ans << std::endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <iostream>

int sum_each_digit() {
  char x[5];
  int ans = 0;
  std::cin >> x;
  if (x[0] == '0')
    return -1;
  for (int i = 0; x[i] != '\\0'; i++) {
    ans += (int)x[i] - 48;
  }
  return ans;
}

int main() {
  int ans;
  while (true) {
    ans = sum_each_digit();
    if (ans == -1)
      break;
    std::cout << ans << std::endl;
  }

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

#include <cstdio>
using namespace std;
int main() {
  char str;

  int flag = 0;
  while (1) {
    int sum = 0;
    while ((str = getchar()) != '\\n') {
      sum += str - '0';
    }
    if (sum == 0) {
      break;
    } else {
      printf("%d\\n", sum);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int main() {
  char str;
  int sum = 0;
  int flag = 0;
  while (1) {
    scanf(" %c", &str);
    if (str == '0' && flag == 0) {
      break;
    }
    sum += (int)str;

    flag = 1;
    if (str == '\\n') {
      printf("%d\\n", sum);
      sum = 0;
      flag = 0;
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  for (;;) {
    int ans = 0;
    char c;
    for (;;) {
      scanf("%c", &c);
      if (c == '\\n') {
        break;
      } else {
        ans += c - '0';
      }
    }
    if (ans)
      printf("%d\\n", ans);
    if (!ans)
      break;
  }
  return 0;
}

Error: 1

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  for (;;) {
    int ans = 0;
    char c;
    for (;;) {
      scanf("%c", &c);
      if (c == '\\n') {
        if (ans) {
          printf("%d\\n", ans);
          break;
        } else {
          exit(1);
        }
      } else {
        ans += c - '0';
      }
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, i, s;
  string str;
  while (1) {
    cin >> str;
    int num = 0;
    if (str == "0")
      break;
    for (i = 0; i < str.size(); i++) {
      n = str[i] - '0';
      num += n;
    }
    cout << num << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long s, i, number;
  while (1) {
    cin >> number;
    i = 0;
    if (number == 0)
      break;
    for (s = number; s > 0; s /= 10) {
      i += s % 10;
    }
    cout << i << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

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


Error: -11

Fixed submission:

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

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

int main() {
  string s;
  while (cin >> s, (s.length() > 1 || s[0] != '0')) {
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
      sum += s[i] - '0';
    }
    cout << sum << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  while (cin >> n, n) {
    stringstream ss;
    ss << n;
    string s = ss.str();
    int sum = 0;
    for (int i = 0; i < s.length(); i++) {
      sum += s[i] - '0';
    }
    cout << sum << endl;
  }

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

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  while (cin >> str) {
    if (str[0] == '0')
      break;

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

Error: 0

Fixed submission:

#include <cstdio>

int main(void) {
  while (1) {
    char *num;
    int ans = 0;
    int i = 0;

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

    while (num[i] != '\\0') {
      ans += (int)(num[i] - '0');
      i++;
    }

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

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

#include <cstdio>

int main() {
  char value[1000];

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

      for (int i = 0; i < 1000; i += 1) {
        if (value[i] == '\\0')
          break;
        sum += value[i] - '0';
      }
      printf("%d\\n", sum);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  char t;
  while (1) {
    scanf("%c", &t);
    if (t == 0)
      break;

    int sum;
    if (t != '\\n') {
      int T = int(t);
      sum += T;
    } else {
      printf("%d\\n", sum);
    }
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {

  string string;
  int sum, i, j = 0;
  int sum_list[1000] = {0};

  while (1) {
    cin >> string;
    if (string == "0") {
      break;
    }
    sum = 0;
    for (i = 0; i < string.size(); i++) {
      sum += string[i] - '0';
    }
    sum_list[j++] = sum;
    string.clear();
  }

  for (i = 0; sum_list[i] != 0; i++) {
    cout << sum_list[i] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {

  string string;
  int sum;

  while (string != "0") {
    cin >> string;
    sum = 0;
    for (int i = 0; i < string.size(); i++) {
      sum += string[i] - '0';
    }
    cout << sum << endl;
    string.clear();
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
int main() {
  string num;
  while (1) {
    int sum = 0;
    cin >> num;
    if (num[0] == '0') {
      break;
    }
    for (int i = 0; i < num.size(); i++) {
      sum = sum + num[i] - '0';
    }

    cout << sum << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i = 0, ch;
  while (1) {
    cin >> ch;
    i = i + ch;
    if (ch = 0) {
      break;
    }
  }
  cout << i << endl;

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

// ↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n) n.begin(), n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = {1, 0}, dy[] = {0, 1}, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long> dij;
struct edge {
  long long to, cost;
};
vector<vector<edge>> G;

long long mod_pow(long long a, long long b) {
  long long res = 1, mul = a;
  for (int i = 0; i < 31; ++i) {
    if (b >> i & 1) {
      res *= mul;
      res %= MOD;
    }
    mul = (mul * mul) % MOD;
  }

  return res;
}

void addedge(int from, int to, int cost) {
  G[from].push_back({to, cost});
  G[to].push_back({from, cost});
}

// ↑template↑

long long digits(string h) {
  long long res = 0;
  for (int i = 0; i < h.length(); ++i) {
    res += h[i] - '0';
  }
  return res;
}

int main() {
  while (1) {
    string n;
    cin >> n;
    if (n == "0") {
      break;
    }
    cout << digits(n) << endl;
  }
}


Error: TLE

Fixed submission:

// ↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n) n.begin(), n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = {1, 0}, dy[] = {0, 1}, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long> dij;
struct edge {
  long long to, cost;
};
vector<vector<edge>> G;

long long mod_pow(long long a, long long b) {
  long long res = 1, mul = a;
  for (int i = 0; i < 31; ++i) {
    if (b >> i & 1) {
      res *= mul;
      res %= MOD;
    }
    mul = (mul * mul) % MOD;
  }

  return res;
}

void addedge(int from, int to, int cost) {
  G[from].push_back({to, cost});
  G[to].push_back({from, cost});
}

// ↑template↑

long long digits(long long n) {
  long long ans = 0;
  while (n) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}

int main() {
  while (1) {
    long long n;
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << digits(n) << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  string n;
  while (1) {
    cin >> n;
    if (n == "0")
      break;
    int sum = 0;
    rep(i, n.size()) { sum += (int)(n[i] - '0'); }
    cout << sum << endl;
  }
}

Error: TLE

Fixed submission:

#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vec;

int main() {
  string n;
  while (1) {
    cin >> n;
    int sum = 0;
    rep(i, n.size()) { sum += (int)(n[i] - '0'); }
    cout << sum << endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

//???????????????????????????Aizu??§???runnning
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int b, i;
  int sum = 0;
  char x[1001]; //?????????

  while (1) {
    cin >> x;
    // x=0?????¨?????????
    sum = 0;
    if (x[0] == '0')
      break;

    for (i = 0; x[i] != 0; i++) {
      b = x[i] - '0'; //?????????x?????????i?????°????????????
      sum += b;
    }
    cout << sum << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

//???????????????????????????Aizu??§???runnning
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int b, i;
  int sum = 0;
  char x[1001]; //?????????

  while (1) {
    cin >> x;
    // x=0?????¨?????????
    sum = 0;
    if (x[0] == 0)
      break;

    for (i = 0; x[i] != 0; i++) {
      b = x[i] - '0'; //?????????x?????????i?????°????????????
      sum += b;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02416 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
int main() {
  char str[1001];
  while (true) {
    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: 0

Fixed submission:

#include <cstdio>
#include <cstring>
int main() {
  char str[5];
  while (true) {
    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 <stdio.h>
using namespace std;
int main() {
  char num[1001];
  while (1) {
    int a = 0;
    scanf("%s", num);
    if (num[0] == '0')
      break;
    for (int i = 0; num[i] != '\\0'; i++) {
      a += num[i] - '0';
    }
    printf("%d\\n", a);
  }
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  char num[1001];
  while (1) {
    int a = 0;
    scanf("%s", num);
    if (num[0] == 0)
      break;
    for (int i = 0; num[i] != '\\0'; i++) {
      a += num[i] - '0';
    }
    printf("%d\\n", a);
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
int main() {
  std::string number;
  while (std::getline(std::cin, number)) {
    int count = 0, c = 0;
    int a = number[0] - '0';
    if (a == 0)
      break;
    for (int dd = 0; dd < number.size(); dd++) {
      char b = number[dd];
      c = b - '0';
      count = count + c;
    }
    std::cout << count << std::endl;
    number.clear();
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {
  char a;
  int b;
  int x = 0;
  while (true) {
    int d = 0;
    int c = 0;
    while (true) {
      std::cin >> a;
      if (d == 0 && a == '0') {
        x = 1;
      }
      if (a == '\\n')
        break;
      b = a - '0';
      c = c + b;
      d++;
    }
    if (x == 1)
      break;
    std::cout << c << std::endl;
  }
}
Problem p02416 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    char b[1001] = "0";
    cin.getline(b, sizeof(b));
    char c[strlen(b)];
    strcpy(c, b);
    if (c[0] != '0') {
      int x = 0;
      for (int k = 0; k < strlen(c); k++) {
        int n;
        n = c[k] - '0';
        x += n;
      }
      cout << x << endl;
    } else {
      break;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    char b[1000] = "0";
    cin.getline(b, sizeof(b));
    char c[strlen(b)];
    strcpy(c, b);
    if (c[0] != '0') {
      int x = 0;
      for (int k = 0; k < strlen(c); k++) {
        int n;
        n = c[k] - '0';
        x += n;
      }
      cout << x << endl;
    } else {
      break;
    }
  }

  return 0;
}