UVa 340 Master-Mind Hints

/* coder: ACboy date: 2010-2-24 result: 1AC description: UVa 340 Master-Mind Hints */ #include <iostream> using namespace std; // 标记i位置的元素是否已被匹配。 int vis[1010]; // 用来保存每一个guess code。 int temp[1010]; // 用来保存最初的code。 int original[1010]; // 用来保存strong match 和 weak match的个数。 int a, b; int main() { int i, j; int n; int count = 0; #ifndef freopen("340.txt", "r", stdin); while (cin >> n) { if (n == 0) break; else { cout << "Game " << ++count << ":" << endl; for (i = 1; i <= n; i++) { cin >> original[i]; } for (i = 1; i <= n; i++) { cin >> temp[i]; } while (temp[1] != 0) { a = 0; b = 0; memset(vis, 0, sizeof(vis)); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) if (!vis[j]) { if (temp[i] == original[j] && i == j) { vis[j] = 1; a++; break; } else if (temp[i] == original[j] && i != j && temp[j] != original[j] && temp[i] != original[i]) { vis[j] = 1; b++; break; } } } cout << " (" << a << "," << b << ")" << endl; for (i = 1; i <= n; i++) { cin >> temp[i]; } } } } return 0; }

你可能感兴趣的:(2010)