The general meaning of the question is that there is an unknown 4-digit n. The question shows several groups of 3 4-digit a B c, A indicates a 4-digit, and B indicates that a has several digits to guess, C indicates that a has several numbers correctly. whether N can be introduced for these conditions. If n is available, n is output; otherwise, not sure is output.
At the beginning, I still wanted to construct N according to the conditions, but I gave up after thinking about it. It was too complicated. Suddenly I found that it would be 4 digits and each time I gave the conditions would not exceed 100 times, direct reference of N, 1000 ~ 9999, time is enough. It is important to note that N conditions cannot be introduced. N conditions may not be found, or N conditions that meet the conditions are found to have multiple. some details should be noted in the code.
The Code is as follows:
# Include <set>
# Include <map>
# Include <queue>
# Include <stack>
# Include <math. h>
# Include <string>
# Include <vector>
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <limits. h>
# Include <string. h>
# Include <algorithm>
# Include <functional>
Using namespace STD;
Int A [105], B [105], C [105];
Int judge (int n, int I, int A [], int B [], int C []) {
Int A [4];
A [0] = N/1000;
A [1] = n % 1000/100;
A [2] = n % 1000% 100/10;
A [3] = n % 1000% 100% 10;
Int AA [4];
AA [0] = A [I]/1000;
AA [1] = (a [I] % 1000)/100;
AA [2] = A [I] % 1000% 100/10;
AA [3] = A [I] % 1000% 100% 10;
Int vis [4]; // indicates the nth K-digit number of a [I ].
Memset (VIS, 0, sizeof (VIS ));
Int ans = 0; // you can guess the number of digits.
Int sum = 0; // number of occurrences at the correct position
For (int K = 0; k <4; k ++ ){
If (A [k] = AA [k])
Sum ++;
For (int kk = 0; KK <4; KK ++)
If (A [k] = AA [Kk] &! Vis [Kk]) {
Ans ++;
Vis [Kk] = 1;
Break; // find an exit now
}
}
If (ANS = B [I] & sum = C [I]) return 1;
Return 0;
}
Int main (){
Int N;
While (scanf ("% d", & N ){
For (INT I = 0; I <n; I ++)
Scanf ("% d", & A [I], & B [I], & C [I]);
Int ans = 0, sum = 0, T;
For (INT I = 1000; I <10000; I ++ ){
For (Int J = 0; j <n; j ++ ){
Ans = 0;
If (! Judge (I, j, A, B, C ))
Break;
Ans = 1;
}
// N that meets the conditions
If (ANS ){
T = I;
Sum ++;
}
If (sum> 1) break; // n cannot be determined if more than one occurrence occurs.
}
If (sum> 1 | sum = 0) printf ("Not Sure \ n ");
Else printf ("% d \ n", t );
}
Return 0;
}
Hoj1172 Problem Solving report