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

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

#include <algorithm>
#include <numeric>
#include <vector>

int main() {
  int n;
  std::vector<int64_t> a(10000);
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::int64_t sum = 0;
  /*auto [min, max]*/ auto minmax =
      std::minmax_element(a.begin(), a.begin() + n);
  sum = std::accumulate(a.begin(), a.end(), (std::int64_t)0);
  printf("%lld %lld %lld\\n", *minmax.first, *minmax.second, sum);
}


Error: WA

Fixed submission:

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

#include <algorithm>
#include <numeric>

int main() {
  int n;
  std::int64_t a[10000];
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  std::int64_t sum = 0;
  auto minmax = std::minmax(a + 0, a + n - 1);
  sum = std::accumulate(a + 0, a + n, 0);
  printf("%lld %lld %lld\\n", *minmax.first, *minmax.second, sum);
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#define nMAX 10000
#define aMAX 1000000
using namespace std;

int main(void) {
  int n, a[nMAX];
  long maxv, minv, sum;

  do {
    cin >> n;
  } while (n <= 0 || n > nMAX);

  while (1) {
    int flag = 1;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] > aMAX || a[i] < -1 * aMAX)
        flag = 0;
    }
    if (flag == 1)
      break;
  }

  maxv = -1 * aMAX;
  minv = a[0];

  for (int i = 0; i < n; i++) {
    maxv = max(maxv, (long)a[i]);
    minv = min(minv, (long)a[i]);
    sum += a[i];
  }

  cout << minv << " " << maxv << " " << sum << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
#define nMAX 10000
#define aMAX 1000000

int main(void) {
  int n, a[aMAX], minv, maxv, sum;

  do {
    cin >> n;
  } while (n >= 0 || n > nMAX);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  maxv = -1 * aMAX;
  minv = a[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, a[i]);
    minv = min(minv, a[i]);
    sum += a[i];
  }

  printf("%d %d %d\\n", minv, maxv, sum);

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  long long n, sum = 0, a[10000];
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  cout << a[0] << ' ' << a[n - 1] << ' ' << sum << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int n, sum = 0, a[100000000];
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  cout << a[0] << ' ' << a[n - 1] << ' ' << sum << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

int main() {
  int n, min, max;
  long long sum;
  // std::vector<int> v;
  std::cin >> n;
  int v[n];

  for (int i = 0; i < n; i++) {
    std::cin >> v[i];
  }
  min = v[0];
  max = v[0];
  sum = 0;
  for (int j = 0; j < n; j++) {
    if (v[j] < min) {
      min = v[j];
    }
    if (max < v[j]) {
      max = v[j];
    }
    sum += v[j];
  }
  std::cout << min << " " << max << " " << sum << std::endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

int main() {
  int n, min, max, sum;
  std::vector<int> v;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> v[i];
  }
  min = v[0];
  max = v[0];
  sum = 0;
  for (int j = 0; j < n; j++) {
    if (v[j] < min) {
      min = v[j];
    }
    if (max < v[j]) {
      max = v[j];
    }
    sum += v[j];
  }
  std::cout << min << " " << max << " " << sum << std::endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[100000];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, max, min;
  long long sum = 0;
  int a[i];
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    sum = sum + a[i];
    if (i == 1) {
      max = a[i];
      min = a[i];
    } else {
      if (max < a[i]) {
        max = a[i];
      }
      if (min > a[i]) {
        min = a[i];
      }
    }
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
#include <vector>

int main() {
  long long int n, a, sum, max, low;
  max = -1000000;
  low = 1000000;
  sum = 0;
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> a;
    sum = sum + a;
    if (max < a) {
      max = a;
    }
    if (low > a) {
      low = a;
    }
  }
  std::cout << low << " " << max << " " << sum << std::endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long a, h, l, s;
  cin >> a;
  h = a;
  l = a;
  s = 0;
  while (a != 0) {
    s = s + a;
    if (h < a) {
      h = a;
    } else if (a < s) {
      s = a;
    }
    cin >> a;
  }
  cout << l << " " << h << " " << s << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  long n, i, a[10001], max, min, sum;

  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sum = a[1];
  min = a[1];
  max = a[1];
  for (i = 2; i <= n; i++) {
    sum = sum + a[i];
    if (a[i] < min)
      min = a[i];
    if (a[i] > max)
      max = a[i];
  };
  cout << min << " " << max << " " << sum << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, i, a[1000], max, min, sum;

  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sum = a[1];
  min = a[1];
  max = a[1];
  for (i = 2; i <= n; i++) {
    sum = sum + a[i];
    if (a[i] < min)
      min = a[i];
    if (a[i] > max)
      max = a[i];
  };
  cout << min << " " << max << " " << sum << endl;

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

#include <cmath>
#include <iostream>

using namespace std;

int main(void) {

  int n;
  cin >> n;

  long min = 1000000;
  long max = -1000000;
  long sum = 0;

  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    sum += a;
    if (min > a)
      min = a;
    if (max < a)
      max = a;
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, sum;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  cout << v[0] << " " << v[n - 1] << " ";
  for (int x : v) {
    sum += x;
  }
  cout << sum << endl;
  return 0;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  long long a[10001] = {0};
  int n;
  long long min;
  long long max;
  int i;
  long long sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  min = a[0];
  for (i = 0; i < n; i++) {
    if (min > a[i])
      min = a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  max = a[0];
  for (i = 0; i < n; i++) {
    if (max < a[i])
      max = a[i];
  }
  for (i = 0; i < n; i++)
    sum = sum + a[i];
  cout << min;
  cout << " ";
  cout << max;
  cout << " ";
  cout << sum;
  cout << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  long long a[1000] = {0};
  int n;
  long long min;
  long long max;
  int i;
  long long sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  min = a[0];
  for (i = 0; i < n; i++) {
    if (min > a[i])
      min = a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  max = a[0];
  for (i = 0; i < n; i++) {
    if (max < a[i])
      max = a[i];
  }
  for (i = 0; i < n; i++)
    sum = sum + a[i];
  cout << min;
  cout << " ";
  cout << max;
  cout << " ";
  cout << sum;
  cout << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long n, i, a[10000], min = 1000000, max = -1000000, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < min) {
      min = a[i];
    }
    if (a[i] > max) {
      max = a[i];
    }
    sum += a[i];
  }
  cout << min << " " << max << " " << sum << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, a[1000], b, c, d, min = 1000000, max = -1000000, sum = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] < min) {
      min = a[i];
    }
    if (a[i] > max) {
      max = a[i];
    }
    sum += a[i];
  }
  cout << min << " " << max << " " << sum << endl;
}
Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int i = 0, n, a;
  long min = 1000000, max = -1000000, total = 0;

  cin >> n;

  while (i < n) {
    cin >> a;

    if (min > a)
      min = a;
    if (max < a)
      max = a;
    total += a;
    i++;
  }
  cout << min << " " << max << " " << total << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i = 0, n, a;
  long min = 100000, max = -100000, total = 0;

  cin >> n;

  while (i < n) {
    cin >> a;

    if (i = 0)
      min = max = a;
    if (min > a)
      min = a;
    if (max < a)
      max = a;
    total += a;
    i++;
  }
  cout << min << " " << max << " " << total << endl;

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

#include <iostream>
using namespace std;

int main() {
  int n, i;
  cin >> n;
  int a[n];

  for (i = 0; i <= n - 1; i++)
    cin >> a[i];
  for (i = n - 1; i > 0; i--)
    cout << a[i] << " ";
  cout << a[0] << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, a[n], i, j;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> a[i];

  for (j = n; j >= 1; j--) {
    if (j != 1)
      cout << a[j] << " ";
    else
      cout << a[j] << endl;
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N 100

int A[MAX_N];
int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = N - 1; i >= 0; i--) {
    cout << A[i];
    if (i != 0)
      cout << " ";
    if (i == 0)
      cout << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
#define MAX_N 100

int A[MAX_N];
int main(int argc, char *argv[]) {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = N - 1; i >= 0; i++) {
    cout << A[i];
    if (i != 0)
      cout << " ";
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  vector<int> v;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  for (int i = N - 1; i >= 0; i--) {
    cout << v[i];
    if (i == 0)
      cout << endl;
    else
      cout << " ";
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  std::vector<int> v;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  for (int i = N - 1; i >= 0; i++) {
    cout << v[i];
    if (i == 0)
      cout << endl;
    else
      cout << " ";
  }
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, i = 0;
  int a[100];
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i != 0)
      cout << " ";
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i = 0;
  int a[100];
  cin >> n;

  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i != n - 1)
      cout << " ";
  }

  while (1)
    ;

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

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

using namespace std;

int main() {
  size_t n;
  int *ptr, *a, i;
  cin >> n;
  ptr = (int *)calloc(n, sizeof(int));
  if (ptr == NULL)
    exit(EXIT_FAILURE);
  a = ptr;
  for (i = 0; i < (int)n; i++) {
    cin >> *(a + i);
  }
  for (i = (int)n - 1; i >= 0; i--) {
    cout << *(a + i);
    if (i > 0)
      cout << " ";
  }
  cout << endl;
}

Error: WA

Fixed submission:

#include <cstdlib>
#include <iostream>

using namespace std;

int main() {
  size_t n;
  int *ptr, *a, i;
  cin >> n;
  ptr = (int *)calloc(n, sizeof(int));
  if (ptr == NULL)
    exit(EXIT_FAILURE);
  (int)n;
  for (i = 1; i <= n; i++) {
    cin >> *a;
    a++;
  }
  for (i = n; i >= 1; i--) {
    cout << *(a + i - 1) << " ";
  }
  cout << "\\b\\n";
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int work[n];
  for (int i = 0; i < n; i++) {
    cin >> work[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    cout << work[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int work[n];
  for (int i = n - 1; n >= 0; i--) {
    cout << work[i] << " ";
  }
  cout << "\\b" << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int a[100];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int j = 0; j < n - 1 - j; j++)
    swap(a[j], a[n - 1 - j]);
  for (int k = 0; k < n; k++)
    if (k == 0)
      cout << a[k];
    else
      cout << " " << a[k];
  cout << endl;

  return (0);
}


Error: TLE

Fixed submission:

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

int main() {
  int H, W, X;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0)
      break;
    else
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          X = i + j;
          if (X % 2 == 0)
            cout << "#";
          else
            cout << ".";
        }
        cout << endl;
      }
    cout << endl;
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int a[100], size;
  cin >> size;
  for (int i = 0; i < size; i++)
    cin >> a[i];

  for (int i = size - 1; i > 0; i--)
    cout << a[i] << " ";
  cout << a[0] << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[100], size;
  cin >> size;
  for (int i = 0; i < size; i++)
    cin >> a[i];
  for (int i = size - 1; i >= 0; i++)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, m;
  int a[1000];
  cin >> n;
  // a = (int *)malloc(sizeof(int) * n);

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

  for (int i = n - 1; i > 0; i--) {
    cout << a[i] << " ";
  }
  cout << a[0];
  cout << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, m;
  int a[10];
  cin >> n;
  // a = (int *)malloc(sizeof(int) * n);

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

  for (int i = n - 1; i > 0; i--) {
    cout << a[i] << " ";
  }
  cout << a[0];
  cout << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
int main(void) {
  int n;
  int a[1000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i > 0; i--) {
    printf("%d ", a[i]);
  }
  printf("%d\\n", a[0]);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
int main(void) {
  int n;
  int a[1000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i > 0; i++) {
    printf("%d ", a[i]);
  }
  printf("%d\\n", a[0]);
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
int main(void) {
  // Here your code !
  int n;
  scanf("%d", &n);
  int nums[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &nums[i]);
  }
  for (int i = 0; i < n; i++) {

    if (i == n - 1) {
      printf("%d\\n", nums[n - 1 - i]);
    } else {
      printf("%d ", nums[n - 1 - i]);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
int main(void) {
  // Here your code !
  int n;
  scanf("%d", &n);
  int nums[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", nums[i]);
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", nums[n - 1 - i]);
    if (i == n - 1) {
      printf("%d\\n", nums[n - 1 - i]);
    }
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  int n;
  int a[100];

  cin >> n;
  for (int i = n - 1; i >= 0; i--) {
    cin >> a[i];
  }

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


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int n;
  int *a;

  cin >> n;
  for (int i = n - 1; i >= 0; i--) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int i, b[n];

  for (i = 0; i < n; i++) {
    cin >> b[i];
  }

  for (i = n - 1; i >= 0; i--) {
    cout << b[i];
    if (i != 0)
      cout << " ";
  }

  cout << endl;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, n, b[n];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> b[i];
  }

  for (i = n - 1; i >= 0; i--) {
    cout << b[i] << ' ';
  }

  cout << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int day[n];

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

  for (int i = n - 1; i >= 0; i--) {
    cout << day[i];

    if (i == 0) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int day[n];

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

  for (int i = n - 1;; i--) {
    if (i < 0) {
      cout << day[i];
    }
    cout << day[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, a[100], i;
  cin >> n;
  for (i = n - 1; i >= 0; i--) {
    cin >> a[i];
  }
  for (i = 0; i < n - 1; i++) {
    cout << a[i] << " ";
  }
  cout << a[i];
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, a[100], i;
  for (;;) {
    cin >> n;
    for (i = n - 1; i >= 0; i--) {
      cin >> a[i];
    }
    for (i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
  }
}
Problem p02407 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, i, chain[100];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> chain[i];
  }
  for (i = n - 1; i >= 0; i--) {
    cout << chain[i];
    if (i == 0)
      break;
    cout << " ";
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  while (1) {
    int n, i;
    cin >> n;
    // int  chain[100];
    //  int *chain = new int[n];
    //  delete [] chain;

    vector<int> chain(n); // vector????????£??????????????????

    // for ( i = n - 1; i >= 0;
    // i--)????????£???????????????????????£??????????????????
    for (i = 0; i < n; i++) {
      cin >> chain[i];
    }
    reverse(chain.begin(), chain.end()); //??????????????????

    for (i = 0; i < n; i++)
      cout << chain.at(i) << " ";
    cout << endl;
  }
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = n - 1; i > 0; i--)
    cout << a[i] << " ";
  cout << a[0] << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i;
  cin >> n;
  int x[n];
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
  i = n;
  while (true) {
    i--;
    cout << x[i] << " ";
    if (i == 1)
      break;
  }
  cout << x[i - 1] << endl;
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int n, a[100] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1) {
      cout << a[i];
    } else {
      cout << " " << a[i];
    }
  }
  cout << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int n, a[5] = {0};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1) {
      cout << a[i];
    } else {
      cout << " " << a[i];
    }
  }
  cout << endl;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int i, n;
  int arr[100] = {0};

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }

  for (i = 0; i < (n / 2); i++) {
    int temp = arr[i];
    arr[i] = arr[(n - 1) - i];
    arr[(n - 1) - i] = temp;
  }

  for (i = 0; i < n; i++) {
    if (i) {
      printf(" ");
    }
    printf("%d", arr[i]);
  }
  printf("\\n");
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <stdio.h>

int main(void) {
  int i, n;
  int arr[] = {};

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }

  for (i = 0; i < (n / 2); i++) {
    int temp = arr[i];
    arr[i] = arr[(n - 1) - i];
    arr[(n - 1) - i] = temp;
  }

  for (i = 0; i < n; i++) {
    if (i) {
      printf(" ");
    }
    printf("%d", arr[i]);
  }
  printf("\\n");
  return 0;
}
Problem p02407 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int k, a[100];

  cin >> k;

  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }

  for (int i = k - 1; i >= 0; i--) {
    if (i != k - 1)
      cout << " ";
    cout << a[i];
  }
  cout << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  int a[k];

  cin >> k;

  for (int i = 0; i < k; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < k; i++) {
    a[i] = a[k - i];
  }
  cout << a[k] << endl;

  return 0;
}