prithivMLmods/Coder-Stat huggingface dataset:
Problem p02413 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[100][100] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>

int main() {
  int r, c, i;
  std::cin >> r >> c;
  int list[101][101] = {0};
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      std::cin >> i;
      list[a][b] = i;
      list[a][c] = list[a][c] + i;
      list[r][b] = list[r][b] + i;
      list[r][c] = list[r][c] + i;
    }
  }
  for (int d = 0; d <= r; d++) {
    for (int e = 0; e <= c; e++) {
      if (e < c) {
        std::cout << list[d][e] << " ";
      } else {
        std::cout << list[d][e];
      }
    }
    std::cout << std::endl;
  }
  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, m, l, num;
  cin >> n >> m >> l;
  int A[n][m], B[m][l];
  for (int a = 0; a < 100000000000; a++) {
    for (int b = 0; b < m; b++) {
      cin >> num;
      A[a][b] = num;
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> num;
      B[a][b] = num;
    }
  }
  long long sum = 0;
  for (int a = 0; a < n; a++) {
    for (int c = 0; c < l; c++) {
      for (int b = 0; b < m; b++) {
        sum = sum + A[a][b] * B[b][c];
      }
      cout << sum;
      sum = 0;
      if (c != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, m, l, num;
  cin >> n >> m >> l;
  int A[n][m], B[m][l];
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < m; b++) {
      cin >> num;
      A[a][b] = num;
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> num;
      B[a][b] = num;
    }
  }
  long long sum = 0;
  for (int a = 0; a < n; a++) {
    for (int c = 0; c < l; c++) {
      for (int b = 0; b < m; b++) {
        sum = sum + A[a][b] * B[b][c];
      }
      cout << sum;
      sum = 0;
      if (c != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  long long A[1000][1000], B[1000][1000], C[1000][1000];

  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> A[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      cin >> B[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C[i][j] = 0;
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j)
        cout << " ";
      cout << C[i][j];
    }
    cout << endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  long long A[100][100], B[100][100], C[100][100];

  cin >> n >> m >> l;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> A[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < l; j++)
      cin >> B[i][j];

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      C[i][j] = 0;
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j)
        cout << " ";
      cout << C[i][j];
    }
    cout << endl;
  }

  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  long int n, m, l, A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m;) {
      for (int k = 0; k < l; k++) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << C[i][j] << " ";
      else
        cout << C[i][j] << endl;
    }
  }

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long int n, m, l, A[100][100], B[100][100], C[100][100] = {};
  cin >> n >> m >> l;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> B[i][j];
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < l; k++) {
        C[i][k] += A[i][j] * B[j][k];
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << C[i][j] << " ";
      else
        cout << C[i][j] << endl;
    }
  }

  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  long int n, m, l, a[100][100], b[100][100], r[100][100], i, j, k;
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      r[i][j] = 0;
    }
  }
  cin >> n >> m >> l;
  if (n < 100 || m < 100 || l < 100) {
    cout << "Too Large" << endl;
    return 1;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] > 10000) {
        cout << " Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> b[i][j];
      if (b[i][j] > 10000) {
        cout << "Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        r[i][j] += (a[i][k] * b[k][j]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << r[i][j];
      if (j != l - 1)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long int n, m, l, a[100][100], b[100][100], r[100][100], i, j, k;
  for (i = 0; i < 100; i++) {
    for (j = 0; j < 100; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      r[i][j] = 0;
    }
  }
  cin >> n >> m >> l;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] > 10000) {
        cout << " Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      cin >> b[i][j];
      if (b[i][j] > 10000) {
        cout << "Too Large" << endl;
        return 1;
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        r[i][j] += (a[i][k] * b[k][j]);
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      cout << r[i][j];
      if (j != l - 1)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int a[100][100];
  int b[100][100];
  int c[100][100] = {};

  for (int i = 1; i <= n; i++) {
    for (int g = 1; g <= m; g++) {
      cin >> a[i][g];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int g = 1; g <= l; g++) {
      cin >> b[i][g];
    }
  }

  for (int h = 1; h <= l; h++) {
    for (int i = 1; i <= n; i++) {
      for (int g = 1; g <= m; g++) {
        c[i][h] += a[i][g] * b[g][h];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int g = 1; g <= l; g++) {
      cout << c[i][g];
      if (g < l) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}


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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int a[200][200];
  int b[200][200];
  long long c[200][200] = {};

  for (int i = 1; i <= n; i++) {
    for (int g = 1; g <= m; g++) {
      cin >> a[i][g];
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int g = 1; g <= l; g++) {
      cin >> b[i][g];
    }
  }

  for (int h = 1; h <= l; h++) {
    for (int i = 1; i <= n; i++) {
      for (int g = 1; g <= m; g++) {
        c[i][h] += a[i][g] * b[g][h];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int g = 1; g <= l; g++) {
      cout << c[i][g];
      if (g < l) {
        cout << " ";
      }
    }
    cout << endl;
  }

  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int A[10000][10000], B[10000][10000], C[10000][10000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> B[a][b];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for (int c = 0; c < n; c++) {
    for (int d = 0; d < l - 1; d++) {
      cout << C[c][d] << " ";
    }
    cout << C[c][l - 1] << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  int A[100][100], B[100][100];
  long long int C[1000][1000];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  for (int a = 0; a < m; a++) {
    for (int b = 0; b < l; b++) {
      cin >> B[a][b];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
  for (int c = 0; c < n; c++) {
    for (int d = 0; d < l - 1; d++) {
      cout << C[c][d] << " ";
    }
    cout << C[c][l - 1] << endl;
  }
  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int n, m, l;
  cin >> n >> m >> l;
  int ue[100][100] = {};
  int sit[100][100] = {};
  int kam[10000][10000] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ue[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> sit[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        kam[i][j] += ue[i][k] * sit[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      cout << kam[i][j];
      if (j != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int n, m, l;
  cin >> n >> m >> l;
  long long ue[101][101] = {};
  long long sit[101][101] = {};
  long long kam[101][101] = {};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> ue[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> sit[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        kam[i][j] += ue[i][k] * sit[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      cout << kam[i][j];
      if (j != l - 1)
        cout << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p02414 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#define V 100
int main() {
  int i, j, k;
  int n, m, l;
  int a[V][V], b[V][V];
  long int c[V][V];

  scanf("%d %d %d", &n, &m, &l);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      a[i][j] = 0;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      b[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      c[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      scanf("%d", &b[i][j]);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      if (j = 0) {
        printf("%li", c[i][j]);
      } else {
        printf("% li", c[i][j]);
      }
    }
    printf("\n");
  }
}


Fixed submission:
#include <stdio.h>
#define V 100
int main() {
  int i, j, k;
  int n, m, l;
  int a[V][V], b[V][V];
  long int c[V][V];

  scanf("%d %d %d", &n, &m, &l);

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      a[i][j] = 0;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      b[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      c[i][j] = 0;
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      scanf("%d", &b[i][j]);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      if (j == 0) {
        printf("%li", c[i][j]);
      } else {
        printf("% li", c[i][j]);
      }
    }
    printf("\n");
  }
}
Problem p02414 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  long a[100][100], b[100][100], c[100][100] = {{0}};
  int n, m, l;

  cin >> n >> m >> l;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int k = 1; k <= l; k++) {
      cin >> b[j][k];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      for (int k = 1; k <= m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      if (j == 1)
        cout << c[i][j];
      else
        cout << " " << c[i][j];
    }
    cout << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  long a[105][105], b[105][105], c[105][105] = {{0}};
  int n, m, l;

  cin >> n >> m >> l;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int j = 1; j <= m; j++) {
    for (int k = 1; k <= l; k++) {
      cin >> b[j][k];
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      for (int k = 1; k <= m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= l; j++) {
      if (j == 1)
        cout << c[i][j];
      else
        cout << " " << c[i][j];
    }
    cout << endl;
  }

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char s;
  while (1) {
    cin >> s;
    if (isalpha(s)) {
      if (islower(s))
        cout << (char)toupper(s);
      else if (isupper(s))
        cout << (char)tolower(s);
    } else {
      cout << s;
    }
    if (s == '\n')
      break;
  }
  return 0;
}

Fixed submission:
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char s;
  while (1) {
    scanf("%c", &s);
    if (isalpha(s)) {
      if (islower(s))
        cout << (char)toupper(s);
      else if (isupper(s))
        cout << (char)tolower(s);
    } else {
      cout << s;
    }
    if (s == '\n')
      break;
  }
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
  }
}


Fixed submission:
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\n')
      break;
  }
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>;
// 入出力を行う関数が使える//(scanf,printf)
#include <cctype>;
// 文字の種類の判定や文字の変換を行う関数を使うことができる//

int main() {
  char ch;

  while (true) {
    scanf("%c", ch);
    // 文字（1文字）として入力する//
    if (isalpha(ch)) {
      // chがアルファベットならtrueを返す//
      if (islower(ch))
        printf("%c", toupper(ch));
      // chが小文字ならtrueを返す// //chの大文字を返す//
      else
        printf("%c", tolower(ch));
      // chの小文字を返す//
    } else
      printf("%c", ch);
    // アルファベット以外はそのまま出力//

    if (ch == '\n')
      break;
    // 終端文字が現れたら終了//
  }
  return 0;
}


Fixed submission:
#include <cstdio>;
// 入出力を行う関数が使える//(scanf,printf)
#include <cctype>;
// 文字の種類の判定や文字の変換を行う関数を使うことができる//

int main() {
  char ch;

  while (true) {
    scanf("%c", &ch);
    // 文字（1文字）として入力する//
    if (isalpha(ch)) {
      // chがアルファベットならtrueを返す//
      if (islower(ch))
        printf("%c", toupper(ch));
      // chが小文字ならtrueを返す// //chの大文字を返す//
      else
        printf("%c", tolower(ch));
      // chの小文字を返す//
    } else
      printf("%c", ch);
    // アルファベット以外はそのまま出力//

    if (ch == '\n')
      break;
    // 終端文字が現れたら終了//
  }
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>;
// 入出力を行う関数が使える//(scanf,printf)
#include <cctype>;

int main() {
  char ch;

  while (true) {
    scanf("%c,&ch");
    if (isalpha(ch)) {
      // chがアルファベットならtrueを返す//
      if (islower(ch))
        printf("%c", toupper(ch));
      // chが小文字ならtrueを返す// //chの大文字を返す//
      else
        printf("%c", tolower(ch));
      // chの小文字を返す//
    } else
      printf("%c", ch);
    // アルファベット以外はそのまま出力//

    if (ch == '\n')
      break;
    // 終端文字が現れたら終了//
  }
  return 0;
}


Fixed submission:
#include <cstdio>;
// 入出力を行う関数が使える//(scanf,printf)
#include <cctype>;

int main() {
  char ch;

  while (true) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      // chがアルファベットならtrueを返す//
      if (islower(ch))
        printf("%c", toupper(ch));
      // chが小文字ならtrueを返す// //chの大文字を返す//
      else
        printf("%c", tolower(ch));
      // chの小文字を返す//
    } else
      printf("%c", ch);
    // アルファベット以外はそのまま出力//

    if (ch == '\n')
      break;
    // 終端文字が現れたら終了//
  }
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  char ch, ch2;

  while (1) {
    scanf("%c", &ch);

    if (islower(ch)) {
      ch2 = toupper(ch);
      cout << ch2;
    } else {
      ch2 = tolower(ch);
      cout << ch2;
    }
    if (ch == ' \n') {
      break;
    }
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  char ch, ch2;

  while (1) {
    scanf("%c", &ch);

    if (islower(ch)) {
      ch2 = toupper(ch);
      cout << ch2;
    } else {
      ch2 = tolower(ch);
      cout << ch2;
    }

    if (ch == '\n') {
      break;
    }
  }

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    cin >> ch;
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\n')
      break;
  }
  return 0;
}


Fixed submission:
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);

    if (ch == '\n')
      break;
  }
  return 0;
}
Problem p02415 (Python)

Buggy submission (status: Runtime Error):
print(input().swapcase())

s = input()

for c in s:
    if c.islower():
        print(c.upper(), end="")
    else:
        print(c.lower(), end="")
print()


Fixed submission:
s = input()

for c in s:
    if c.islower():
        print(c.upper(), end="")
    else:
        print(c.lower(), end="")
print()
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main(void) {
  char s;
  while (1) {
    scanf("%c", &s);
    if (islower(s) == 1) {
      cout << toupper(s);
    } else if (isupper(s) == 1) {
      cout << tolower(s);
    } else {
      cout << s;
    }
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

int main(void) {
  char s;
  while (1) {
    scanf("%c", &s);
    if (s == '\n') {
      break;
    }
    if (islower(s)) {
      printf("%c", toupper(s));
    } else if (isupper(s)) {
      printf("%c", tolower(s));
    } else {
      cout << s;
    }
  }
  cout << endl;
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: 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() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else
      printf("%c", tolower(ch));
    if (ch == '\0')
      break;
  }
}

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() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else
      printf("%c", tolower(ch));
    if (ch == '\n')
      break;
  }
}
Problem p02415 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {

  string mozi;

  getline(cin, mozi);

  for (int i = 0; (int)mozi.size(); i++) {

    if (islower(mozi[i])) {
      mozi[i] = toupper(mozi[i]);
    } else if (isupper(mozi[i])) {
      mozi[i] = tolower(mozi[i]);
    }
  }
  cout << mozi << endl;

  return 0;
}


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

int main() {

  string mozi;

  getline(cin, mozi);

  for (int i = 0; i < (int)mozi.size(); i++) {

    if (islower(mozi[i])) {
      mozi[i] = toupper(mozi[i]);
    } else if (isupper(mozi[i])) {
      mozi[i] = tolower(mozi[i]);
    }
  }
  cout << mozi << endl;

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else if (isupper(ch))
      printf("%c", tolower(ch));
    else if (!isalpha(ch))
      printf("%c", ch);
    else if (ch == '\n')
      break;
  }

  return 0;
}


Fixed submission:
#include <cctype>
#include <cstdio>

int main() {
  char ch;

  while (1) {
    scanf("%c", &ch);
    if (islower(ch))
      printf("%c", toupper(ch));
    else if (isupper(ch))
      printf("%c", tolower(ch));
    else if (!isalpha(ch))
      printf("%c", ch);
    if (ch == '\n')
      break;
  }

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  string komozi("abcdefghijklmnopqrstuvwxyz");
  string oomozi("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  char inp;
  char retsu[1000000];

  for (int i = 0;; i++) {
    inp = getchar();
    if (inp == '.') {
      retsu[i] = '.';
      retsu[i + 1] = '\0';
      break;
    }
    if (komozi.find(inp) != -1)
      retsu[i] = oomozi[komozi.find(inp)];
    else if (oomozi.find(inp) != -1)
      retsu[i] = komozi[oomozi.find(inp)];
    else
      retsu[i] = inp;
  }

  cout << retsu << endl;

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void) {

  string komozi("abcdefghijklmnopqrstuvwxyz");
  string oomozi("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  char inp;
  char retsu[1000000];

  for (int i = 0;; i++) {
    inp = getchar();
    if (inp == '\n') {
      retsu[i + 1] = '\0';
      break;
    }
    if (komozi.find(inp) != -1)
      retsu[i] = oomozi[komozi.find(inp)];
    else if (oomozi.find(inp) != -1)
      retsu[i] = komozi[oomozi.find(inp)];
    else
      retsu[i] = inp;
  }

  cout << retsu << endl;

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
  }
  return 0;
}


Fixed submission:
#include <cctype>
#include <cstdio>
using namespace std;
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '\n')
      break;
  }
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <cstdio>
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '/n')
      break;
  }
  return 0;
}

Fixed submission:
#include <cctype>
#include <cstdio>
int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);
    if (isalpha(ch)) {
      if (islower(ch))
        printf("%c", toupper(ch));
      else
        printf("%c", tolower(ch));
    } else
      printf("%c", ch);
    if (ch == '\n')
      break;
  }
  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char ch;
  while (1) {
    scanf(" %c", &ch);

    if (isupper(ch))
      cout << (char)tolower(ch);
    else if (islower(ch))
      cout << (char)toupper(ch);
    else {
      if (ch == '\n')
        break;
      cout << ch;
    }
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <cctype>
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  char ch;
  while (1) {
    scanf("%c", &ch);

    if (isupper(ch))
      cout << (char)tolower(ch);
    else if (islower(ch))
      cout << (char)toupper(ch);
    else {
      if (ch == '\n')
        break;
      cout << ch;
    }
  }
  cout << endl;

  return 0;
}
Problem p02415 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <ctype.h>
#include <stdio.h>
int main() {
  char a[1200];
  int i;
  while (1) {
    scanf("%c", &a[i]);
    if (isupper(a[i])) {
      printf("%c", tolower(a[i]));
    } else if (islower(a[i])) {
      printf("%c", toupper(a[i]));
    } else {
      printf("%c", a[i]);
    }
  }
  return 0;
}

Fixed submission:
#include <ctype.h>
#include <stdio.h>
int main() {
  char a[1200];
  int i;
  while (1) {
    scanf("%c", &a[i]);
    if (a[i] == '\n') {
      printf("\n");
      break;
    }
    if (isupper(a[i])) {
      printf("%c", tolower(a[i]));
    } else if (islower(a[i])) {
      printf("%c", toupper(a[i]));
    } else {
      printf("%c", a[i]);
    }
  }
  return 0;
}
Problem p02416 (C++)

Buggy submission (status: 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;
}


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 (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: 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;
}


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 (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}


Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: 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);
  }
}


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 (status: Runtime Error):
#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;
}

Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: 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;
}

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 (status: 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;
}


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 (status: 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;
    int sum = 0;
    rep(i, n.size()) { sum += (int)(n[i] - '0'); }
    cout << sum << endl;
  }
}

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;
    if (n == "0")
      break;
    int sum = 0;
    rep(i, n.size()) { sum += (int)(n[i] - '0'); }
    cout << sum << endl;
  }
}
Problem p02416 (C++)

Buggy submission (status: 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[i] == '0')
      break;
    d = 0;
    for (int j = 0; j < num.length(); j++) {
      d += num[j] - '0';
    }
    cout << d << "\n";
  }

  return 0;
}

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[0] == '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 (status: Runtime Error):
#include <cctype>
#include <cstdio>

int main() {
  int sum;
  char line[6];

  while (true) {
    sum = 0;
    scanf("%s", line);
    for (int i = 0; isdigit(line[i]); i++) {
      sum += line[i] - '0';
    }

    if (sum == 0) {
      break;
    }

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

  return 0;
}


Fixed submission:
#include <cctype>
#include <cstdio>

int main() {
  int sum;
  char line[1002];

  while (true) {
    sum = 0;
    scanf("%s", line);
    for (int i = 0; isdigit(line[i]); i++) {
      sum += line[i] - '0';
    }

    if (sum == 0) {
      break;
    }

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

  return 0;
}
Problem p02416 (C++)

Buggy submission (status: 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;
}

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 (status: 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;
}

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 (status: Runtime Error):
#include <iostream>
#include <string>
int main() {
  using namespace std;
  string s;
  int ans, x, y, size, i, j;
  ans = 0;
  i = 0;
  x = 1;
  while (x) {
    cin >> s;
    if (s == "0") {
      break;
    }
    x = stoi(s);
    size = s.size();
    for (j = 0; j < size; j++) {
      y = s[j] - '0';
      ans = ans + y;
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
int main() {
  using namespace std;
  string s;
  int ans, x, y, size, i, j;
  ans = 0;
  i = 0;
  x = 1;
  while (x) {
    cin >> s;
    if (s == "0") {
      break;
    }
    size = s.size();
    for (j = 0; j < size; j++) {
      y = s[j] - '0';
      ans = ans + y;
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
Problem p02416 (C++)

Buggy submission (status: Time Limit Exceeded):
#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);
  }
}


Fixed submission:
#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);
  }
}
Problem p02416 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  string str;
  int count = 0;
  int sum;
  int a;
  int offset;
  string splitString;
  vector<string> strList;

  while (1) {
    cin >> str;

    if (str == "0") {
      break;
    }

    strList.push_back(str);
    count++;
  }

  for (int i = 0; i < count; i++) {
    offset = 0;
    sum = 0;
    while (offset <= strList[i].length()) {
      splitString = strList[i].substr(offset, 8);
      a = stoi(splitString);
      while (a > 0) {
        sum += a % 10;
        a /= 10;
      }
      offset += 8;
    }
    cout << sum << "\n";
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  string str;
  int count = 0;
  int sum;
  int a;
  int offset;
  string splitString;
  vector<string> strList;

  while (1) {
    cin >> str;

    if (str == "0") {
      break;
    }

    strList.push_back(str);
    count++;
  }

  for (int i = 0; i < count; i++) {
    offset = 0;
    sum = 0;
    while (offset < strList[i].length()) {
      splitString = strList[i].substr(offset, 8);
      a = stoi(splitString);
      while (a > 0) {
        sum += a % 10;
        a /= 10;
      }
      offset += 8;
    }
    cout << sum << "\n";
  }

  return 0;
}
Problem p02416 (C++)

Buggy submission (status: Time Limit Exceeded):
#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;
}

Fixed submission:
#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;
}
Problem p02416 (C++)

Buggy submission (status: 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("%s\n", sum);
  }
  return 0;
}


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("%d\n", sum);
  }
  return 0;
}
Problem p02416 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int i;
  char number[5] = {0};
  int sum = 0;

  while (1) {
    sum = 0;
    cin >> number;

    for (i = 0; number[i] != '\0'; i++) {
      sum += number[i] - '0';
    }
    if (number[0] == '0')
      break;
    cout << sum << "\n";
  }
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int i;
  char number[1001] = {0};
  int sum = 0;

  while (1) {
    sum = 0;
    cin >> number;

    for (i = 0; number[i] != '\0'; i++) {
      sum += number[i] - '0';
    }
    if (number[0] == '0')
      break;
    cout << sum << "\n";
  }
}
Problem p02416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char str[1001];
  while (1) {
    scanf("%s", str);
  }
}


Fixed submission:
#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);
  }
}
Problem p02416 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <math.h>
#include <stdio.h>

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

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

    if (sum == 0) {
      break;
    } else {
      printf("%d\n", sum);
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <math.h>
#include <stdio.h>

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

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

    if (sum == 0) {
      break;
    } else {
      printf("%d\n", sum);
    }
  }

  return 0;
}
Problem p02416 (C++)

Buggy submission (status: 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);
  }
}

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);
  }
}