UVa 340 Master-Mind Hints

不知道他想干干嘛
权当熟悉JAVA

import java.util.Scanner;

public class Main {
  public static void main(String args[]) {
    final int maxn = 1000 + 9;
    Scanner cin = new Scanner(System.in);
    for (int t = 1; ; t++) {
      int n = cin.nextInt();
      if (n == 0) break;
      System.out.printf("Game %d:\n", t);
      int[] a = new int[maxn];
      for (int i = 0; i < n; i++) {
        a[i] = cin.nextInt();
      }
      for (;;) {
        int ansa = 0;
        int[] b = new int[maxn];
        for (int i = 0; i < n; i++) {
          b[i] = cin.nextInt();
          if (a[i] == b[i]) ansa++;
        }
        if (b[0] == 0) break;
        int ansb = 0;
        for (int d = 1; d < 10; d++) {
          int c1 = 0, c2 = 0;
          for (int i = 0; i < n; i++) {
            if (a[i] == d) c1++;
            if (b[i] == d) c2++;
          }
          ansb += Math.min(c1, c2);
        }
        System.out.printf(" (%d,%d)\n", ansa, ansb - ansa);
      }
    }
  }
}

你可能感兴趣的:(UVa 340 Master-Mind Hints)