Second question of the Golden October online programming competition: decryption, golden October

Source: Internet
Author: User

Second question of the Golden October online programming competition: decryption, golden October
Question details:

Xiaoqiang is a student and a hacker. Shortly after the examination, he was surprised to find that his Advanced Mathematics Subject had crashed, so he decisively intruded into the website of the school's Ministry of Education. During the intrusion, he found that the score-related content is an encrypted file consisting of n numbers. After analysis, the key of the encrypted file is the minimum number of binary digits in n. However, because the number is large, Xiaoqiang hopes that you can help him get the key. Fortunately, the score will be changed before the score is published.

Input description:

The input consists of multiple groups of data. The first behavior of each group of data is a number of n (1 <=n <= 10 ^ 5), indicating the number of data, the n integers in the second row represent each number in the file (1 <= each number <= 10 ^ 9 ). End with a file.

Output description:

For each group of data to output a row, first output the number of data sets, and then output the binary containing the minimum number of 1. If there are multiple numbers that meet the condition, the minimum output is the one.



Q & A description:

Input example:

5

3 2 4 5 6

Output example:

Case 1: 2


Resolution: This question is clear and does not involve any algorithm classes. The only difference is to calculate the number of binary 1 in an integer. This method is too many and the simplest is shift, then we can accumulate, and the rest is the logic judgment.

However, it seems that the challenge was successful only after four submissions. In the past, there was a space between Case and 1, and a space between colon and 2, ....

Paste your own code

# Include <iostream> using namespace std; int BitCount (unsigned int n) {unsigned int c = 0; for (c = 0; n; ++ c) {n & = (n-1); // clears 1} return c;} int main () {int n, m, mincount, minnumber, T = 1; while (cin> n) {// enter n integers for (int I = 0; I <n; ++ I) {cin> m; // calculate the number of integers int count = BitCount (m) in the binary m; // initialize mincount and minnumber for the first time if (I = 0) {mincount = count; minnumber = m;} else {// judge and update the minimum value and the number of 1 in the minimum binary if (count <mincount | (count = mincount & m <minnumber )) {minnumber = m; mincount = count ;}}// output Casecout <"Case" <T <":" <minnumber <endl; T ++ ;}}



C language programming first question correction and analysis second question Programming

I:
# Include <stdio. h>
# Include <string. h>
Void main ()
{
Char a [80] = "";
Int I = 0, k = 0, m = 0, n = 0;
Gets ();
For (int p = 0; p <strlen (a); p ++) // you have modified it, implemented a loop using a for statement, and checked each one.
{// The Variable p is defined here, because you have defined the global variable I;
If (a [p] = 32) // The ASIC code of the space is 32
{
I ++;
}
Else if (a [p]> = '0' & a [p] <= '9 ')
{
M ++;
}
Else if (a [p]> = 97 & a [p] <= 123) | (a [p]> = 65 & a [p] <= 96 ))
{
N ++;
}
Else
{
K ++;
}
}
Printf ("number characters: % d \ n letter characters: % d \ n space characters: % d \ n other characters: % d \ n", m, n, I, k );
}
The second question is very simple. Think about it.

45 people in a class participated in a math competition. 35 people answered the first question, 27 answered the second question, and 41 answered the third question,

Number of people who answered the first question = 45-35 = 10
Number of people who answered the second question = 45-27 = 18
Number of people who answered the third question = 45-41 = 4
Number of people who answered the fourth question = 45-38 = 7

At least 45-10-18-4-7 = 6 people answered in all four questions
Up to 27 people

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.