投資錢景>買台積電就對了工程師靠存股年領百萬股息吉隆坡最便宜行程一覽表老伯送飲料 遭學生糾察...
2013-05-28 23:10:40 人氣(418) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVa] 10019 - Funny Encryption Method

0
收藏
0
推薦

 

Funny Encryption Method

The Problem

History :
A student from ITESM Campus Monterrey plays with a new encryption method for numbers. These 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 be 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 be 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 student failed Computational Organization, that’s why this student asked the judges of ITESM Campus Monterrey internal ACM programming Contest to ask for the numbers of 1’s bits of this two representations so that he can continue playing.

Task :
You have to write a program that read a Number and give as output the number b1 and b2

The Input

The first line will contain a number N which is the number of cases that you have to process. Each of the following N Lines ( 0<N<=1000) will contain the number M (0<M<=9999, in decimal representation)  which is the number the student wants to encrypt.

The Output

You will have to output N lines, each containing the number b1 and b2 in that order, separated by one space  corresponding to that lines number to crypt

Sample Input

3
265
111
1234

Sample Output

3 5
6 3
5 5


#include <stdio.h>

int main() {
    int t;
    char s[10];
    scanf("%d", &t);
    while(t--) {
        scanf("%s", s);
        int x1, x2, b1 = 0, b2 = 0;
        sscanf(s, "%d", &x1);
        sscanf(s, "%x", &x2);
        while(x1)
            b1 += x1&1, x1 /= 2;
        while(x2)
            b2 += x2&1, x2 /= 2;
        printf("%d %d\n", b1, b2);
    }
    return 0;
}

10019Funny Encryption Method
台長:Morris
人氣(418) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][heap] 10954 - Add All
此分類上一篇:[UVA] 12503 - Robot Instructions

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文