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

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int code[4], line, hit, bro;
  while (cin >> code[0]) {
    hit = 0;
    bro = 0;
    for (int i = 1; i < 4; ++i) {
      cin >> code[i];
    }
    for (int i = 0; i < 4; ++i) {
      cin >> line;
      if (code[i] == line) {
        ++hit;
      } else {
        for (int i2 = 0; i2 < 4; ++i2) {
          if (code[i2] == line) {
            ++bro;
          }
        }
      }
    }
    cout << hit << " " << bro << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int code[4], line, hit, bro;
  while (true) {
    hit = 0;
    bro = 0;
    for (int i = 0; i < 4; ++i) {
      cin >> code[i];
    }
    for (int i = 0; i < 4; ++i) {
      cin >> line;
      if (code[i] == line) {
        ++hit;
      } else {
        for (int i2 = 0; i2 < 4; ++i2) {
          if (code[i2] == line) {
            ++bro;
          }
        }
      }
    }
    cout << hit << " " << bro << endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

/***** ?????¬???????????¬?????? *****/

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

#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
  int a[4], b[4];
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    set<int> s1, s2;
    rep(i, 0, 4) s1.insert(a[i]);
    rep(i, 0, 4) s2.insert(b[i]);

    int hit = 0, blow = 0;
    rep(i, 0, 4) {
      if (a[i] == b[i])
        hit++;
      else if (s1.count(b[i]) != 0)
        blow++;
    }

    printf("%d %d\\n", hit, blow);
  }
  return 0;
}

Error: TLE

Fixed submission:

/***** ?????¬???????????¬?????? *****/

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

#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a, b) (abs((a) - (b)) < EPS)
#define EQV(a, b) (EQ((a).X, (b).X) && EQ((a).Y, (b).Y))
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
  set<int> s1, s2;
  int a[4], b[4];
  while (1) {
    rep(i, 0, 4) {
      cin >> a[i];
      s1.insert(a[i]);
    }
    rep(i, 0, 4) {
      cin >> b[i];
      s2.insert(b[i]);
    }

    int hit = 0, blow = 0;
    rep(i, 0, 4) {
      if (a[i] == b[i])
        hit++;
      else if (s1.count(b[i]) != 0)
        blow++;
    }

    printf("%d %d\\n", hit, blow);
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a[4], b[4];
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    int hit = 0, blow = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] == b[j]) {
          if (i == j) {
            hit++;
          } else {
            blow++;
          }
        }
      }
    }
    cout << hit << " " << blow << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (1) {
    int hit = 0, blow = 0;
    vector<int> a, b;
    int input;
    for (int i = 0; i < 4; i++) {
      cin >> input;
      a.push_back(input);
    }
    for (int i = 0; i < 4; i++) {
      cin >> input;
      b.push_back(input);
    }
    vector<int>::iterator a_ite, b_ite;
    for (a_ite = a.begin(); a_ite != a.end(); a_ite++) {
      for (b_ite = b.begin(); b_ite != b.end(); b_ite++) {
        if (*a_ite == *b_ite)
          blow++;
      }
    }
    a_ite = a.begin();
    b_ite = b.begin();
    for (; a_ite != a.end(); a_ite++) {
      if (*a_ite == *b_ite)
        hit++;
      b_ite++;
    }
    blow -= hit;

    cout << hit << " " << blow << endl;
  }

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

#include <stdio.h>

int main(void) {
  char line[80];
  int a[4], b[4];

  while (true) {
    if (fgets(line, sizeof line, stdin) == NULL) {
      return 0;
    }
    if (sscanf(line, "%d %d %d %d", &(a[0]), &(a[1]), &(a[2]), &(a[3])) != 4) {
      return 0;
    }

    if (fgets(line, sizeof line, stdin) == NULL) {
      return 0;
    }
    if (sscanf(line, "%d %d %d %d", &(b[0]), &(b[1]), &(b[2]), &(b[3])) != 4) {
      return 0;
    }

    int h = 0;
    int w = 0;

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] == b[j]) {
          if (i == j) {
            h++;
          } else {
            w++;
          }
        }
      }
    }
    printf("%d %d\\n", h, w);
  }

  return 0;
}

Error: 1

Fixed submission:

#include <stdio.h>

int main(void) {
  char line[80];
  int a[4], b[4];

  while (true) {
    if (fgets(line, sizeof line, stdin) == NULL) {
      return 1;
    }
    if (sscanf(line, "%d %d %d %d", &(a[0]), &(a[1]), &(a[2]), &(a[3])) != 4) {
      return 1;
    }

    if (fgets(line, sizeof line, stdin) == NULL) {
      return 1;
    }
    if (sscanf(line, "%d %d %d %d", &(b[0]), &(b[1]), &(b[2]), &(b[3])) != 4) {
      return 1;
    }

    int h = 0;
    int w = 0;

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] == b[j]) {
          if (i == j) {
            h++;
          } else {
            w++;
          }
        }
      }
    }
    printf("%d %d\\n", h, w);
  }

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

#include <iostream>
using namespace std;
int main() {
  int a[4][50], b[4][50], hit, blow, n;
  n = 0;
  while (cin >> a[0][n] >> a[1][n] >> a[2][n] >> a[3][n] >> b[0][n] >>
         b[1][n] >> b[2][n] >> b[3][n]) {
    n++;
  }

  for (int i = 0; i < n; i++) {
    hit = blow = 0;
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        if (a[j][i] == b[k][i]) {
          if (j == k) {
            hit++;
          } else {
            blow++;
          }
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[4][50], b[4][50], hit, blow, n;
  for (int i = 0; i < 50; i++) {
    cin >> a[0][i] >> a[1][i] >> a[2][i] >> a[3][i] >> b[0][i] >> b[1][i] >>
        b[2][i] >> b[3][i];
    int t = 0;
    for (int j = 0; j < 4; j++) {
      if (a[j][i] != 0) {
        t = 1;
        j = 4;
      }
      if (b[j][i] != 0) {
        t = 1;
        j = 4;
      }
    }
    if (t == 0) {
      n = i;
      i = 50;
    }
  }
  for (int i = 0; i < n; i++) {
    hit = blow = 0;
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        if (a[j][i] == b[k][i]) {
          if (j == k) {
            hit++;
          } else {
            blow++;
          }
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int a[4];
int b[4];

int main() {
  int n, m;
  while (~scanf("%d%d%d%d", &a[0], &a[1], &a[2], &a[3])) {
    scanf("%d%d%d%d", &b[0], &b[1], &b[2], &b[3]);
    int i;
    n = m = 0;
    for (i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] == b[j] && i == j) {
          n++;
        }
        if (a[i] == b[j] && i != j) {
          m++;
        }
      }
    }
    cout << n << " " << m << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int a[4], b[4];
  int d[10];
  int n, m;
  while (1) {
    n = m = 0;
    memset(d, 0, sizeof(d));
    for (int i = 0; i < 4; i++)
      scanf("%d", &a[i]);
    for (int i = 0; i < 4; i++) {
      scanf("%d", &b[i]);
      if (a[i] == b[i])
        n++;
      else {
        d[a[i]]++;
        d[b[i]]++;
      }
    }

    if (a[0] == EOF)
      break;
    if (n == 4)
      printf("%d %d\\n", n, m);
    else {
      for (int i = 0; i <= 9; i++) {
        if (d[i] == 2)
          m++;
      }
      printf("%d %d\\n", n, m);
    }
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int a[4], b[4];

  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    // hit
    int hit = 0;
    for (int i = 0; i < 4; i++)
      hit += (a[i] == b[i]);

    // blow
    int blow = 0;
    for (int i = 0; i < 4; i++)
      blow += ((a[i] == b[0]) || (a[i] == b[1]) || (a[i] == b[2]) ||
               (a[i] == b[3]));

    cout << hit << " " << blow - hit << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a[4], b[4];

  while (1) {
    for (int i = 0; i < 4; i++)
      cin >> a[i];
    for (int i = 0; i < 4; i++)
      cin >> b[i];

    // hit
    int hit = 0;
    for (int i = 0; i < 4; i++)
      hit += (a[i] == b[i]);

    // blow
    int blow = 0;
    for (int i = 0; i < 4; i++)
      blow += ((a[i] == b[0]) || (a[i] == b[1]) || (a[i] == b[2]) ||
               (a[i] == b[3]));

    cout << hit << " " << blow - hit << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int A[4], B[4];
  while (cin >> A[0] >> A[1] >> A[2] >> A[3],
         cin >> B[0] >> B[1] >> B[2] >> B[3]) {
    int hit = 0, blow = 0;
    bool check[10] = {false};
    // cin >> A[0] >> A[1] >> A[2] >> A[3];
    // cin >> B[0] >> B[1] >> B[2] >> B[3];
    for (int i = 0; i < 4; i++)
      if (A[i] == B[i])
        hit++;
    for (int i = 0; i < 4; i++)
      check[A[i]] = true;
    for (int i = 0; i < 4; i++)
      if (A[i] != B[i] && check[B[i]])
        blow++;
    cout << hit << " " << blow << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int A[4], B[4];
  while (1) {
    int hit = 0, blow = 0;
    bool check[10] = {false};
    cin >> A[0] >> A[1] >> A[2] >> A[3];
    cin >> B[0] >> B[1] >> B[2] >> B[3];
    for (int i = 0; i < 4; i++)
      if (A[i] == B[i])
        hit++;
    for (int i = 0; i < 4; i++)
      check[A[i]] = true;
    for (int i = 0; i < 4; i++)
      if (A[i] != B[i] && check[B[i]])
        blow++;
    cout << hit << " " << blow << endl;
  }
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  int a[4], b[4], Hit, Blow;

  while (scanf("%d%d%d%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &b[0], &b[1],
               &b[2], &b[3]) != EOF) {
    Hit = Blow = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {

        if (a[i] == b[j] && i == j)
          Hit++;
        else if (a[i] == b[j] && i != j)
          Blow++;
      }
    }

    cout << Hit << " " << Blow << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int Q, A, qq[4], aa[4], Hit, Blow, num;

  while (1) {

    num = 1000;
    Hit = Blow = 0;

    cin >> Q >> A;
    if (Q == 0 && A == 0)
      break;

    for (int i = 0; i < 4; i++) {

      qq[i] = Q / num % 10;
      aa[i] = A / num % 10;
      num /= 10;
    }

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {

        if (qq[i] == aa[j] && i == j)
          Hit++;
        else if (qq[i] == aa[j] && i != j)
          Blow++;
      }
    }

    cout << Hit << " " << Blow << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int a[4], b[4];
  while (cin >> a[0]) {
    int hit = 0, blow = 0;
    for (int i = 1; i < 4; i++)
      cin >> a[i];
    for (int i = 0; i < 4; i++)
      cin >> b[i];
    for (int k = 0; k < 4; k++) {
      for (int j = 0; j < 4; j++) {
        if (a[k] == b[j]) {
          if (k == j)
            hit++;
          else
            blow++;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int hit[4] = {}, blow[4] = {};
  while (1) {
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < 4; i++) {
      cin >> hit[i];
    }
    for (int i = 0; i < 4; i++) {
      cin >> blow[i];
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (hit[i] == blow[j]) {
          (i == j) ? ans1++ : ans2++;
        }
      }
    }
    cout << ans1 << " " << ans2 << endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int a[4];
  int b[4];

  while ((scanf("%d", &a[0])) != EOF) {
    int hitcount = 0;
    int bcount = 0;

    for (int i = 1; i < 4; i++) {
      scanf("%d", &a[i]);
    }

    for (int i = 0; i < 4; i++)
      cin >> b[i];

    // a???????????????????????????????´????b????????¢??¢?´¢
    for (int i = 0; i < 4; i++) {
      int x = a[i];
      for (int j = 0; j < 4; j++) {
        if (x == b[j]) {
          if (i == j)
            hitcount++;
          else
            bcount++;
        }
      }
    }

    cout << hitcount << " " << bcount << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

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

int main(void) {
  int a[4];
  int b[4];

  while ((scanf("%d", a[0])) != EOF) {
    int hitcount = 0;
    int bcount = 0;

    for (int i = 1; i < 4; i++) {
      scanf("%d", a[i]);
    }

    for (int i = 0; i < 4; i++)
      cin >> b[i];

    // a???????????????????????????????´????b????????¢??¢?´¢
    for (int i = 0; i < 4; i++) {
      int x = a[i];
      for (int j = 0; j < 4; j++) {
        if (x == b[j]) {
          if (i == j)
            hitcount++;
          else
            bcount++;
        }
      }
    }

    cout << hitcount << " " << bcount << endl;
  }

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

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

int main() {
  int a[4];
  int b[4];
  while (cin >> a[0]) {
    for (int i = 1; i < 4; i++)
      cin >> a[i];
    for (int i = 0; i < 4; i++)
      cin >> b[i];

    int hit = 0;
    int blow = 0;

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] != b[j])
          continue;
        if (i == j)
          hit++;
        else
          blow++;
      }
    }
    cout << hit << ' ' << blow << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a[4];
  int b[4];
  while (true) {
    for (int i = 0; i < 4; i++)
      cin >> a[i];
    for (int i = 0; i < 4; i++)
      cin >> b[i];
    if (a[0] == EOF)
      break;

    int hit = 0;
    int blow = 0;

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (a[i] != b[j])
          continue;
        if (i == j)
          hit++;
        else
          blow++;
      }
    }
    cout << hit << ' ' << blow << endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> a(4);
  while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    int hit = 0, blow = 0;
    for (int i = 0; i < 4; i++) {
      int b;
      cin >> b;
      for (int j = 0; j < 4; j++) {
        if (a[j] == b) {
          if (i == j)
            hit++;
          else
            blow++;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
int main() {
  while (true) {
    vector<int> a(4);
    for (int i = 0; i < 4; i++)
      cin >> a[i];
    int hit = 0, blow = 0;
    for (int i = 0; i < 4; i++) {
      int b;
      cin >> b;
      for (int j = 0; j < 4; j++) {
        if (a[j] == b) {
          if (i == j)
            hit++;
          else
            blow++;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int i, j;
  int hit, blow;
  int dataA[4], dataB[4];

  while (scanf("%d", &dataA[0]) != EOF) {

    hit = 0;
    blow = 0;

    for (i = 1; i < 4; i++) {
      scanf("%d", &dataA[i]);
    }

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

    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        if (dataA[i] == dataB[j] && i == j) {
          hit++;
        } else if (dataA[i] == dataB[j] && i != j) {
          blow++;
        }
      }
    }

    printf("%d %d\\n", hit, blow);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int i, j;
  int hit, blow;
  int dataA[4], dataB[4];

  while (scanf("%d", &dataA[0]) != EOF) {

    hit = 0;
    blow = 0;

    for (i = 1; i < 4; i++) {
      scanf("%d", dataA[i]);
    }

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

    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        if (dataA[i] == dataB[j] && i == j) {
          hit++;
        }
      }
    }

    printf("%d %d\\n", hit, blow);
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main() {
  vector<int> a(4);
  vector<int> b(4);
  while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    rep(i, 4) cin >> b[i];
    int hit = 0, blow = 0;
    rep(i, 4) {
      if (a[i] == b[i])
        hit++;
      else {
        rep(j, 4) if (a[j] == b[i]) blow++;
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main() {
  while (1) {
    vector<int> a(4);
    vector<int> b(4);
    rep(i, 4) cin >> a[i];
    rep(i, 4) cin >> b[i];
    int hit = 0, blow = 0;
    rep(i, 4) {
      if (a[i] == b[i])
        hit++;
      else {
        rep(j, 4) if (a[j] == b[i]) blow++;
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a[4], b[4];
  int hit, blow;
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    hit = blow = 0;
    for (int i = 0; i < 4; i++) {
      if (a[i] == b[i]) {
        hit++;
      }
      for (int j = 0; j < 4; j++) {
        if (a[i] == b[j]) {
          blow++;
        }
      }
    }
    blow -= hit;
    cout << hit << " " << blow << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a[4], b[4];
  int hit, blow;
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    hit = blow = 0;
    for (int i = 0; i < 4; i++) {
      if (a[i] == b[i]) {
        hit++;
      }
      for (int j = 0; i < 4; j++) {
        if (a[i] == b[j]) {
          blow++;
        }
      }
    }
    blow -= hit;
    cout << hit << " " << blow << endl;
  }

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

#include <iostream>
int main() {
  int n;
  while (std::cin >> n) {
    int a[4], b[4];
    a[0] = n;
    int eat = 0, bite = 0;
    for (int i = 1; i < 4; i++) {
      std::cin >> a[i];
    }
    for (int i = 0; i < 4; i++) {
      std::cin >> b[i];
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (i == j && a[i] == b[j]) {
          eat++;
        } else if (a[i] == b[j]) {
          bite++;
        }
      }
    }
    std::cout << eat << " " << bite << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
int main() {

  while (1) {
    int a[4], b[4];
    int eat = 0, bite = 0;
    for (int i = 0; i < 4; i++) {
      std::cin >> a[i];
    }
    if (a[0] == 0) {
      break;
    }
    for (int i = 0; i < 4; i++) {
      std::cin >> b[i];
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (i == j && a[i] == b[j]) {
          eat++;
        } else if (a[i] == b[j]) {
          bite++;
        }
      }
    }
    std::cout << eat << " " << bite << std::endl;
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int a1, a2, a3, a4, b1, b2, b3, b4;
  set<int> setA, setB;
  while (cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4) {
    int hit = 0, blow = 0;
    if (a1 == b1) {
      hit++;
    } else {
      setA.insert(a1);
      setB.insert(b1);
    }
    if (a2 == b2) {
      hit++;
    } else {
      setA.insert(a2);
      setB.insert(b2);
    }
    if (a3 == b3) {
      hit++;
    } else {
      setA.insert(a3);
      setB.insert(b3);
    }
    if (a4 == b4) {
      hit++;
    } else {
      setA.insert(a4);
      setB.insert(b4);
    }

    for (int i = 1; i <= 9; ++i) {
      if (setA.count(i) && setB.count(i)) {
        ++blow;
      }
    }

    cout << hit << " " << blow << endl;
    setA.clear();
    setB.clear();
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <set>
using namespace std;
int main() {
  string a, b;
  set<int> aa, bb;
  while (getline(cin, a) && getline(cin, b)) {
    int hit = 0;
    int blow = 0;
    for (int i = 0; i != a.size(); i += 2) {
      if (a[i] == b[i]) {
        ++hit;
      } else {
        aa.insert(a[i] - '0');
        bb.insert(b[i] - '0');
      }
    }
    for (int i = 1; i <= 9; ++i) {
      if (aa.count(i) && bb.count(i)) {
        ++blow;
      }
    }
    cout << hit << " " << blow << endl;
    aa.clear();
    bb.clear();
  }
  return 0;
}
Problem p00025 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a[4], b[4];
  while (cin >> a[0]) {
    int hit = 0, blow = 0;
    for (int i = 1; i < 4; i++)
      cin >> a[i];
    for (int i = 0; i < 4; i++)
      cin >> b[i];
    for (int k = 0; k < 4; k++) {
      for (int j = 0; j < 4; j++) {
        if (a[k] == b[j]) {
          if (k == j)
            hit++;
          else
            blow++;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a[4], b;
  for (int i = 0; i < 4; i++) {
    cin >> a[i];
  }
  while (1) {
    int H = 0, B = 0;
    for (int i = 0; i < 4; i++) {
      cin >> b;
      for (int j = 0; j < 4; j++) {
        if (a[j] == b) {
          if (i == j) {
            H++;
          } else {
            B++;
          }
        }
      }
    }
    if (H == 4)
      break;
    cout << H << " " << B << endl;
    ;
  }
  return 0;
}