#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
bool fr[9][10];
bool fc[9][10];
bool fb[9][10];
int a[9][9];
bool check() {
int i, j;
for (i = 0; i < 9; i++)
for (j = 0; j < 10; j++)
fr[i][j] = fc[i][j] = fb[i][j] = false;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
if (fr[i][a[i][j]] || fc[j][a[i][j]] || fb[i / 3 * 3 + j / 3][a[i][j]])
return false;
fr[i][a[i][j]] = fc[j][a[i][j]] = fb[i / 3 * 3 + j / 3][a[i][j]] = true;
}
}
return true;
}
int main(int argc, char* argv[]) {
int i, j, k, cas;
scanf("%d", &cas);
for (k = 1; k <= cas; k++) {
for (i = 0; i < 9; i++)
for (j = 0; j < 9; j++)
scanf("%d", &a[i][j]);
printf("Case %d:\n", k);
printf("%s\n", check() ? "Yes!" : "No!");
}
return 0;
}
|