UVa 10019 Funny encryption Method (Water ver.)

Source: Internet
Author: User

10019-funny Encryption method

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=960

The Problem

History:
A student from ITESM campus Monterrey plays and a new encryption method for numbers. These are method consist of the following steps:

Steps:example
1 Read the number N to encrypt M = 265
2) interpret N as a decimal number x1= 265 (decimal)
3 Convert The decimal interpretation of N to its binary representation x1= 100001001 (binary)
4 Let B1 is equal to the number of 1 ' s in this binary representation b1= 3
5) interpret N as a hexadecimal number X2 = 265 (hexadecimal)
6 Convert The hexadecimal interpretation of N to its binary representation X2 = 1001100101
7 Let B2 is equal to the number of 1 ' s in the last binary representation B2 = 5
8) The encryption is the result of M xor (B1*B2) M xor (3*5) = 262

This is student failed computational organization, that's why this student asked the judges of ITESM campus Monterrey Interna L ACM Programming Contest to ask for the numbers of 1 ' s bits of this two representations so and he can continue playing.

Task:
You are have to write a program that read a number and give as output the number B1 and B2

The Input

The the A number N which is the number of cases that you have to process. Each of the following N Lines (0<n<=1000) would contain the number M (0<m<=9999, in decimal representation) W Hich is the number of the student wants to encrypt.

The Output

This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45353.htm

You'll have to output N lines, containing of the number B1 and B2 in, separated by one space corresponding To, lines number to crypt

Sample Input

3
265
111
1234

Sample Output

3 5
6 3

5 5

Complete code:

/*0.016s*/
     
#include <cstdio>  
     
inline int bitnum (int num)  
{  
    int count = 0;  
    while (num)  
    {  
        if (num & 1) ++count;  
        Num >>= 1;  
    }  
    return count;  
}  
     
int main ()  
{  
    int t, M, B1, B2;  
    scanf ("%d", &t);  
    while (t--)  
    {  
        scanf ("%d", &m);  
        B1 = Bitnum (m), b2 = 0;  
        while (m)  
        {  
            B2 + = Bitnum (m);  
            M/=;  
        printf ("%d%d\n", B1, B2);  
    }  
    return 0;  
}

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.