Second question of the Golden October online programming competition: decryption

Source: Internet
Author: User
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 ++ ;}}


Second question of the Golden October online programming competition: decryption

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.