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

#include <iostream>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  if (x <= y) {
    while (x != 0) {
      int v;
      v = x;
      x = y % x;
      y = v;
    }
    cout << y << endl;
  } else if (y <= x) {
    while (y != 0) {
      int v;
      v = y;
      y = x % y;
      x = v;
    }
    cout << x << endl;
  }
  return 0;
}

// 解けるけど時間がかかるやつ
/*int main(){
        int x,y;
        cin>>x>>y;
        if(x<=y){
                for(int i = x;i>=1;i--){
                        if(x%i == 0 && y%i == 0){
                                cout<<i<<endl;
                                break;
                        }
                }
        }
        else if(x>=y){
                for(int i = y;i>=1;i--){
                        if(x%i == 0 && y%i == 0){
                                cout<<i<<endl;
                                break;
                        }
                }
        }
        return 0;
}*/


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  if (x <= y) {
    for (int i = x; i >= 1; i--) {
      if (x % i == 0 && y % i == 0) {
        cout << i << endl;
        break;
      }
    }
  } else if (x >= y) {
    for (int i = y; i >= 1; i--) {
      if (x % i == 0 && y % i == 0) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

/* ?´???´?????¢?????´?????????
int gcd(int x,int y) {
  int n = min(x,y);
  for(int d=n;d>=1;d--)
    if(!(x%d || y%d))
      return d;
  return 0;
}
*/
int gcd(int x, int y) {
  if (x < y)
    swap(x, y);
  int r;
  while (y > 0) {
    r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main(void) {
  int x, y;
  cin >> x;
  cin >> y;
  cout << gcd(x, y) << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int gcd(int x, int y) {
  int n = min(x, y);
  for (int d = n; d >= 1; d--)
    if (!(x % d || y % d))
      return d;
  return 0;
}

int main(void) {
  int x, y;
  cin >> x;
  cin >> y;
  cout << gcd(x, y) << '\\n';
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long x, y, c;
  cin >> x >> y;
  if (x < y) {
    c = y;
    y = x;
    x = c;
  }
  c = 0;
  while (x != 0 && y != 0) {
    if (c % 2 == 0) {
      x = x % y;
    } else {
      y = y % x;
    }
    ++c;
  }
  cout << x + y << endl;
  return 0;
}

Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long x, y, c;
  cin >> x >> y;
  if (x < y) {
    c = y;
    y = x;
    x = c;
  }
  c = 0;
  while (!x == 0 || y == 0) {
    if (c % 2 == 0) {
      x = x % y;
    } else {
      y = y % x;
    }
    ++c;
  }
  cout << x + y << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;
int main() {
  int x, y, N1, N2, keepn1, keepn2;
  cin >> x >> y;
  if (x <= y) {
    N1 = y, N2 = x;
  } else {
    N1 = x, N2 = y;
  }

  //========================================================
  while (1) {
    if (N1 % N2 == 0) {
      break;
    }
    keepn1 = N1;
    keepn2 = N2;
    // cout<<N1<<"/"<<N2<<"="<<N1/N2<<"_"<<N1%N2<<endl;
    N1 = keepn2;
    N2 = keepn1 % keepn2;
    // cout<<N1<<" "<<N2<<endl;
  }
  cout << N2 << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int x, y, N, i, answer;
  cin >> x >> y;
  if (x <= y) {
    N = x;
  } else {
    N = y;
  }

  for (i = 1; i < N + 1; i++) { // cout<<i<<" "<<y%i<<" "<<x%i<<endl;
    if (y % i == 0 and x % i == 0) {
      answer = i;
    }
  }
  cout << answer << endl;

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

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

int main() {

  int a, b, result = 0, ab;

  cin >> a >> b;
  if (1 < a && a < b) {
    ab = b % a;
    for (int i = 1; i <= ab; i++) {
      if (ab % i == 0 && a % i == 0)
        result = max(i, result);
    }
  } else if (1 < b && b < a) {
    ab = a % b;
    //	cout << ab << endl;
    for (int i = 1; i <= ab; i++) {
      if (ab % i == 0 && b % i == 0)
        result = max(i, result);
    }
  } else if (a == b)
    result = a;

  cout << result << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int a, b, result = 0, ab;

  cin >> a >> b;
  if (1 < a && a < b) {
    ab = b % a;
    for (int i = 1; i <= a; i++) {
      if (ab % i == 0 && a % i == 0)
        result = max(i, result);
    }
  } else if (1 < b && b <= a) {
    ab = a % b;
    //	cout << ab << endl;
    for (int i = 1; i <= b; i++) {
      if (ab % i == 0 && b % i == 0)
        result = max(i, result);
    }
  }

  cout << result << endl;

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

#include <iostream>
using namespace std;

int main() {
  long x, y, answer;
  cin >> x >> y;
  if (x == y)
    answer = x;
  if (x > y) {
    int m, n, r;
    m = x;
    n = y;
    while (1) {
      r = m % n;
      if (r == 0) {
        answer = n;
        break;
      } else {
        m = n;
        n = r;
      }
    }
  }
  if (x < y) {
    int m, n, r;
    m = y;
    n = x;
    while (1) {
      r = m % n;
      if (r == 0) {
        answer = n;
        break;
      } else {
        m = n;
        n = r;
      }
    }
  }
  cout << answer << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  long x, y, answer;
  cin >> x >> y;
  if (x == y)
    answer = x;
  if (x > y) {
    int m, n, r;
    m = x;
    n = y;
    while (1) {
      r = m % n;
      if (r == 0) {
        answer = n;
        break;
      }
    }
  }
  if (x < y) {
    int m, n, r;
    m = y;
    n = x;
    while (1) {
      r = m % n;
      if (r == 0) {
        answer = n;
        break;
      }
    }
  }
  cout << answer << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int x, y;
  cin >> x >> y;
  if (x < y) {
    swap(x, y);
  }
  while (1) {
    if (x % y == 0)
      break;
    x = x % y;
    if (x < y) {
      swap(x, y);
    }
  }
  cout << y << endl;
  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  int x, y;
  x = max(x, y);
  y = min(x, y);
  while (1) {
    if (x % y == 0)
      break;
    x = x % y;
    x = max(x, y);
    y = min(x, y);
  }
  cout << x << endl;
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Runtime Error

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

void sorts(int *xx, int *yy);

int main() {
  int x, y;
  cin >> x >> y;
  sorts(&x, &y);
  x = x % y;
  if (!x) {
    cout << y << endl;
    return 0;
  }
  int ans = y;
  for (int i = x; i >= 0; i--) {
    if (y % i == 0 && x % i == 0) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

void sorts(int *xx, int *yy) {
  if (*xx < *yy) {
    int temp = *xx;
    *xx = *yy;
    *yy = temp;
  }
  return;
}

Error: 0

Fixed submission:

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

void sorts(int *xx, int *yy);

int main() {
  int x, y;
  cin >> x >> y;
  sorts(&x, &y);
  x = x % y;
  int ans = y;
  for (int i = x; i >= 0; i--) {
    if (y % i == 0 && x % i == 0) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

void sorts(int *xx, int *yy) {
  if (*xx < *yy) {
    int temp = *xx;
    *xx = *yy;
    *yy = temp;
  }
  return;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

//
// Write a program which finds the greatest common divisor of two natural
// numbers a and b
//
#include <iostream>
using namespace std;

void read(int &x, int &y);
int calcGcd(const int x, const int y);
void write(const int gcd);

int main() {
  int x = 0, y = 0;
  int ret = 0;

  read(x, y);
  ret = x > y ? calcGcd(x, y) : calcGcd(y, x);
  write(ret);
}

void read(int &x, int &y) { cin >> x >> y; }

int calcGcd(const int x, const int y) {
  int r = 0;

  if (x == y)
    return x;

  r = x - y;
  if (y == r)
    return r;

  y > r ? calcGcd(y, r) : calcGcd(r, y);
}

void write(const int gcd) { cout << gcd << endl; }

Error: TLE

Fixed submission:

//
// Write a program which finds the greatest common divisor of two natural
// numbers a and b
//
#include <iostream>
using namespace std;

void read(int &x, int &y);
int calcGcd(const int x, const int y);
void write(const int gcd);

int main() {
  int x = 0, y = 0;
  int ret = 0;

  read(x, y);
  ret = x > y ? calcGcd(x, y) : calcGcd(y, x);
  write(ret);
}

void read(int &x, int &y) { cin >> x >> y; }

int calcGcd(const int x, const int y) {
  int r = 0;

  r = x - y;
  if (y == r)
    return r;

  y > r ? calcGcd(y, r) : calcGcd(r, y);
}

void write(const int gcd) { cout << gcd << endl; }
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int gcd(int, int);
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int max = 1;
  int i;
  max = gcd(a, b);
  printf("%d\\n", max);
  return 0;
}
int gcd(int m, int n) {
  int rest;
  int x = (m > n) ? m : n;
  int y = (x == m) ? n : m;
  while (1) {
    rest = x % y;
    if (rest == 0)
      return y;
    x = y;
    y = rest;
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int max = 1;
  int i;
  for (i = 2; i <= a; i++) {
    if (i > b)
      break;
    if (a % i == 0 && b % i == 0)
      max = i;
  }
  printf("%d\\n", max);
  return 0;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, c = 1, d = 1;
  cin >> a >> b;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  if (a >= b) {
    a = a % b;
  }
  while (a > 10 && b > 10 && a % 10 == 0 && b % 10 == 0) {
    a = a / 10;
    b = b / 10;
    d = d * 10;
  }
  for (int i = 1; i < a; i++) {
    if (a % i == 0 && b % i == 0) {
      if (i > c)
        c = i;
    }
  }
  cout << c * d << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c = 0;
  cin >> a >> b;
  if (a == b) {
    cout << a << endl;
    return 0;
  }
  if (a >= b) {
    a = a % b;
    b = b % a;
  }
  for (int i = 1; i < a; i++) {
    if (a % i == 0 && b % i == 0) {
      if (i > c)
        c = i;
    }
  }
  cout << c << endl;
}
Problem p02256 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int gcd(int x, int y) {
  if (x < y) {
    return gcd(y, x);
  } else if (x >= y && x % y != 0) {
    return gcd(x % y, y);
  } else {
    return y;
  }
}
int main() {
  long long int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

long long int gcd(long long int x, long long int y) {
  bool flag = true;
  while (flag) {
    if (x > y) {
      if (x % y != 0) {
        x = x % y;
      }
      if (x % y == 0) {
        return y;
        flag = false;
      }
    }
    if (y > x) {
      if (y % x != 0) {
        y = y % x;
      }
      if (y % x == 0) {
        return x;
        flag = false;
      }
    }
  }
}
int main() {
  long long int x, y;
  cin >> x >> y;
  cout << gcd(x, y) << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int a[101];

int solve(int n) {
  int c = 0;
  int b = 1;
  int damy;
  if (n == 1)
    return c;
  while (1) {
    int f = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] < a[i - 1]) {
        c++;
        f++;
        damy = a[i - 1];
        a[i - 1] = a[i];
        a[i] = damy;
        if (i - 1 == 0)
          break;
      } else if (f > 0 && a[i] >= a[i - 1])
        break;
      else if (i == 1 && f == 0)
        return c;
    }
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int c = solve(n);
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      cout << a[i] << ' ';
    else
      cout << a[i] << endl;
  }
  cout << c << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int a[101];

int solve(int n) {
  int c = 0;
  int b = 1;
  int damy;
  if (n == 1)
    return c;
  while (1) {
    int f = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] < a[i - 1]) {
        c++;
        f++;
        damy = a[i - 1];
        a[i - 1] = a[i];
        a[i] = damy;
        if (i - 1 == 0)
          break;
      } else if (f > 0 && a[i] >= a[i - 1])
        break;
      else if (i == 1 && f == 0)
        return c;
    }
  }
}

int main() {

  ifstream ifs;
  ofstream ofs;
  ifs.open("data.txt");
  ofs.open("result.txt");

  int n;
  ifs >> n;
  for (int i = 0; i < n; i++)
    ifs >> a[i];
  int c = solve(n);
  for (int i = 0; i < n; i++) {
    if (i != n - 1)
      ofs << a[i] << ' ';
    else
      ofs << a[i] << endl;
  }
  ofs << c << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

/***
 *	??????????????????
 *	???????????????????????£???????????£??\\????´?????????????????????§????¬???????????????°?????????
 *	?????????????°?????????£??\\??????????´?????????????????????????????????§?°???¢?????????????????°???????????????
 ****/

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

int main(void) //???????????¢??°
{
  int n;
  cin >> n;

  vector<int> str;
  str.resize(n);

  for (int i = 0; i < n; i++) { //????????\\???
    cin >> str[i];
  }
  //	int k = n-1;

  int cnter = 0;
  for (int i = 0; i < n - 1; ++i) {

    for (int j = 1; j < (n - i); j++) {
      if (str[j] < str[j - 1]) { //????????????????´???¨??????
        int temp = str[j];
        str[j] = str[j - 1];
        str[j - 1] = temp;
        cnter++;
      }
    }
  }
  //	k=j;

  //----------------------------------	???????????????
  for (int i = 0; i < n; i++) {
    cout << str[i];
    if (i != (n - 1)) {
      cout << " ";
    }
  }
  cout << endl;

  cout
      << cnter
      << endl; //???????????°????????¢??°???????????¢?????°??¨?????°??????????????±?????????????????¨?????°???

  return 0;
}

Error: -11

Fixed submission:

/***
 *	??????????????????
 *	???????????????????????£???????????£??\\????´?????????????????????§????¬???????????????°?????????
 *	?????????????°?????????£??\\??????????´?????????????????????????????????§?°???¢?????????????????°???????????????
 ****/

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

int main(void) //???????????¢??°
{
  int n;
  cin >> n;

  vector<int> str;
  str.resize(n);

  for (int i = 0; i < n; i++) { //????????\\???
    cin >> str[i];
  }
  //	int k = n-1;

  int cnter = 0;
  for (int i = 0; i < n - 1; ++i) {

    for (int j = (n - 1); j <= (i + 1); j--) {
      //		for(int j = 1 ; j< (n-i); j++){
      if (str[j] < str[j - 1]) { //????????????????´???¨??????
        int temp = str[j];
        str[j] = str[j - 1];
        str[j - 1] = temp;
        cnter++;
      }
    }
  }
  //	k=j;

  //----------------------------------	???????????????
  for (int i = 0; i < n; i++) {
    cout << str[i];
    if (i != (n - 1)) {
      cout << " ";
    }
  }
  cout << endl;

  cout
      << cnter
      << endl; //???????????°????????¢??°???????????¢?????°??¨?????°??????????????±?????????????????¨?????°???

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

#include <algorithm>
#include <iostream>
using namespace std;
int cnt;
void BubbleSort(int A[], int N) {
  bool flag = true;
  while (flag) {
    flag = false;
    for (int j = N - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        cnt++;
        flag = true;
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cnt = 0;
  BubbleSort(A, N);
  for (int i = 0; i < N; i++) {
    cout << A[i];
    if (i < N - 1)
      cout << " ";
    else
      cout << endl;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int cnt;
void BubbleSort(int a[], int n) {
  bool flag = true;
  while (flag) {
    flag = false;
    for (int j = n - 1; j = 1; j--) {
      if (a[j] < a[j - 1]) {
        swap(a[j], a[j - 1]);
        cnt++;
        flag = true;
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cnt = 0;
  BubbleSort(a, n);
  for (int i = 0; i < n; i++) {
    cout << a[i];
    if (i != n - 1)
      cout << " ";
    else
      cout << "?\\n";
  }
  cout << cnt << "?\\n";
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int bubbleSort(int A[], int N) {
  int sw = 0, i, j, temp;
  bool flag = 1;
  for (i = 0; flag; i++) {
    flag = 0;
    for (j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        temp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = temp;
        sw++;
        flag = 1;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw, i;

  cin >> N;
  for (i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

  for (i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int bubbleSort(int A[], int N) {
  int sw = 0, i, j, temp;
  bool flag = 1;
  for (i = 0; flag; i++) {
    flag = 0;
    for (j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        temp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = temp;
        sw++;
        flag = 1;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw, i;

  scanf("%d", &N);
  for (i = 0; i < N; i++)
    scanf("%d", A[i]);

  sw = bubbleSort(A, N);

  for (i = 0; i < N; i++) {
    if (i > 0)
      printf(" ");
    printf("%d", A[i]);
  }
  printf("\\n%d\\n", sw);

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

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, tmp;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    a.push_back(tmp);
  }

  int flag = 1;
  int swapCount = 0;
  int sortedIndex = 0;

  while (flag == 1) {
    flag = 0;
    for (int i = n - 1; i > sortedIndex; --i)
      if (a[i] < a[i - 1]) {
        swap(a[i], a[i - 1]);
        swapCount++;
        flag = 1;
      }
    sortedIndex++;
  }

  for (int i = 0; i < n - 1; ++i)
    printf("%d ", a[i]);
  printf("%d\\n", a[n - 1]);
  printf("%d\\n", swapCount);
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

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

  int flag = 1;
  int swapCount = 0;
  int sortedIndex = 0;

  while (flag) {
    flag = 0;
    for (int i = (n - 1); n > sortedIndex; i--)
      if (a[i] < a[i - 1]) {
        swap(a[i], a[i - 1]);
        swapCount++;
        flag = 1;
      }
    sortedIndex++;
  }

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

#include <iostream>

using namespace std;
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sw = bubbleSort(A, N);
  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j++) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  sw = bubbleSort(A, N);
  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

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

#include <iostream>

using namespace std;

int bubble_sort(int a[], int n) {
  int c = 0;
  for (int i = 0; i < n; i++) {
    for (int i = 1; i < n; i++) {
      if (a[i - 1] > a[i]) {
        c++;
        swap(a[i - 1], a[i]);
      }
    }
  }
  return c;
}

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int change = bubble_sort(a, n);
  for (int i = 0; i < n - 1; i++) {
    cout << a[i] << ' ';
  }
  cout << a[n - 1] << endl;
  cout << change << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int bubblesort(int A[], int N) {
  // 1 bubbleSort(A, N) // N ??????????´?????????? 0-?????????????????????
  // 2   flag = 1 // ????????£??\\????´?????????¨??????
  // 3   while flag
  // 4     flag = 0
  // 5     for j ??? N-1 ?????? 1 ?????§
  // 6       if A[j] < A[j-1]
  // 7         A[j] ??¨ A[j-1] ?????????
  // 8         flag = 1
  int sw = 0;
  bool flag = 1;
  for (int j = N - 1; flag; j--) {
    flag = 0;
    for (int i = 0; i < N - 1; i--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}
int main() {
  int N, A[100], sw;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  sw = bubblesort(A, N);

  for (int i = 0; i < N; ++i) {
    //???????????????
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  vector<int> List;
  int count = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int Value;
    cin >> Value;
    List.push_back(Value);
  }

  bool Flag = true;

  while (Flag) {
    Flag = false;
    for (int j = n - 1; j > 0; j--) {
      if (List[j] < List[j - 1]) {
        int Temp;
        Temp = List[j];
        List[j] = List[j - 1];
        List[j - 1] = Temp;
        Flag = true;
        count++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (i > 0)
      cout << " ";
    cout << List[i];
  }
  cout << endl;

  cout << count << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  vector<int> List;
  int count = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int Value;
    cin >> Value;
    List.push_back(Value);
  }

  bool Flag = true;

  while (Flag) {
    Flag = false;
    for (int j = n - 1; j > 0; j++) {
      if (List[j] < List[j - 1]) {
        int Temp;
        Temp = List[j];
        List[j] = List[j - 1];
        List[j - 1] = Temp;
        Flag = true;
        count++;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (i > 0)
      cout << " ";
    cout << List[i];
  }
  cout << endl;

  cout << count << endl;
}