The school took an English test. There were 10 non-questions, each entitled 10 points. The answer was expressed as "yes" and 0 as "non. However, after the instructor approved the exam, he found that he missed the exam and the standard answer was lost. Only three papers marked with scores were left on his hand.
Exam 1:
① (3) (4) (6) (7)
0 0 1 0 1 0 1 0 0 0 score: 70
Exam 2:
① (3) (4) (6) (7)
0 1 1 1 0 1 1 1 1 1 score: 50
Exam 3:
① (3) (4) (6) (7)
0 1 1 1 0 0 0 1 1 score: 30
Pending exam approval:
① (3) (4) (6) (7)
0 0 1 1 1 0 0 1 1 1 score :?
Compile 1ProgramCalculate the score of the missing exam based on the three tests.
Let's put it bluntly. There are only 10 questions...
# Include Cstdio >
Int BITs ( Int A) // Calculate how many bits in a is 1
{
Int C = 0 ;
For (C = 0 ; A; c ++ )
{
A=A&(-1);
}
Return C;
}
Int Main ()
{
Int I;
Int A [ 4 ] = {0x0a4,0x1d7,0x1c5,0x0e7,} ;
Int S [ 4 ] = {7,5,3,0} ;
For (I = 0 ; I 1024 ; I ++ ) // Try various answers
{
If ( 10 - BITs ([ 0 ] ^ I) = S [ 0 ] && // A [0] ^ I indicates correcting a [0] According to the answer I. The result 1 is different (that is, the answer is wrong ).
10 - BITs ([ 1 ] ^ I) = S [ 1 ] &&
10 - BITs ([ 2 ] ^ I) = S [ 2 ]) // The answer to all scores may be the correct one.
{
S [ 3 ] = 10 - BITs ([ 3 ] ^ I ); // Calculate the score of the missing batch volume
Printf ( " % D \ n " , S [ 3 ]);
}
}
Return 0 ;
}
The result is quite clever. Although there are multiple possible correct answers, the total score for this paper is 60 --