UVa340 Master-Mind Hints, uva340master-mind
# Include <stdio. h>
# Include <string. h>
# Define MIN (a, B) (a) <(B ))? (A): (B ))
Int main ()
{
Int code [1000];
Int guess [1000];
Int C1 [10]; // number 1 ~ 9 The number of times the code appears. C1 [0] is not used
Int C2 [10]; // number 1 ~ 9 number of occurrences in guess, C2 [0] not used
Int n, I, S, C, game = 0;
While (scanf ("% d", & n) = 1 & n)
{
Memset (C1, 0, sizeof (C1 ));
For (I = 0; I <n; ++ I)
{
Scanf ("% d", code + I );
+ C1 [code [I];
}
Printf ("Game % d: \ n", ++ game );
While (1)
{
S = 0; // Strong Match
Memset (C2, 0, sizeof (C2 ));
For (I = 0; I <n; ++ I)
{
Scanf ("% d", guess + I );
++ C2 [guess [I];
If (guess [I] = code [I])
++ S;
}
If (! Guess [0])
Break;
C = 0; // 1 ~ 9. The total number of concurrent occurrences in code and guess
For (I = 1; I <10; ++ I)
{
If (C1 [I] & C2 [I])
C + = MIN (C1 [I], C2 [I]);
}
Printf ("(% d, % d) \ n", S, C-S );
}
}
Return 0;
}