#include <stdio.h> int all;
Answer count//save group and set character struct mar{char group;
char set;
}MAR[6][6];
Separating the group and row rows to determine the struct group{int count;//record pointer char set[6];//group character}grp[6];
Whether the row and column repeats an int lc (int m, int n, char c) {int i;
for (i=0; i<6; i++) {if (mar[m][i].set==c) return 0;
} for (i=0; i<6; i++) {if (mar[i][n].set==c) return 0;
} return 1;
}//processing the GRP array, judging whether the group repeats int GP (char GR, char c) {int i;
for (i=0; i<grp[gr-' 0 '].count; i++) {if (c==grp[gr-' 0 '].set[i]) return 0;
} return 1;
}//print void print () {printf ("%d\n", ++all);
int I, J;
for (i=0; i<6; i++) {for (j=0; j<6; j + +) printf ("%c", Mar[i][j].set);
printf ("\ n");
}}//Backtracking function, heuristic assignment void set (int m, int n) {//satisfies output if (m>5) {print ();
Return
} int i; Distinguishes between fixed and variable characters if (mar[m][n].set== ' 0 ') {for (i=0; i<6; i++) {if (LC (M, N, i+ ' A ') && GP (Mar[m][n].group, i+ ' a ') {//Judge mar[m][n].set=i+ ' a ';//test grp[mar[m][n].group-' 0 '].set[grp[mar[m][n].group-' 0 '].Count++]=mar[m][n].set;
The corresponding group is incremented by one character set (m+ (n+1)/6, (n+1)%6); mar[m][n].set= ' 0 '; The function exits must be the same as the state, because do not participate in the conditional judgment, often placed behind the function grp[mar[m][n].group-' 0 '].set[--(grp[mar[m][n].group-' 0 '].count)]= ' 0 ';
Note that the group setting character will affect the next heuristic's judgment so it must be restored}} mar[m][n].set= ' 0 ';
} else Set (m+ (n+1)/6, (n+1)%6);
} int main () {int I, j, N, T;
char c;
For (i=0, i<6; i++) {for (j=0; j<6; J + +) {Mar[i][j].group=getchar ();
mar[i][j].set= ' 0 ';
} getchar ();
} scanf ("%d", &n);
while (n--) {scanf ("%d%c", &t,&c);
Mar[t/10][t%10].set=c;
grp[mar[t/10][t%10].group-' 0 '].set[(grp[mar[t/10][t%10].group-' 0 '].count++)]=c;
} set (0,0);
if (all==0) printf ("0\n");
return 0; }