UVa 10019 Funny Encryption Method (water ver.)
来源:互联网 发布:康师傅免流量软件 编辑:程序博客网 时间:2024/06/11 02:01
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 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 cryptSample Input
3265
111
1234
Sample Output
3 56 3
5 5
完整代码:
/*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 % 10);m /= 10;}printf("%d %d\n", b1, b2);}return 0;}
- UVa 10019 Funny Encryption Method (water ver.)
- uva 10019 Funny Encryption Method
- UVa 10019 - Funny Encryption Method
- UVa 10082 WERTYU (water ver.)
- UVa 10696 f91 (water ver.)
- UVa 79 ClockHands (water ver.)
- UVa 11340 Newspaper (water ver.)
- UVa 514 Rails (water ver.)
- UVa 11150 Cola (water ver.)
- UVa 10300 Ecological Premium (water ver.)
- UVa 414 Machined Surfaces (water ver.)
- UVa 490 Rotating Sentences (water ver.)
- UVa 445 Marvelous Mazes (water ver.)
- UVa 488 Triangle Wave (water ver.)
- UVa 10783 Odd Sum (water ver.)
- UVa 457 Linear Cellular Automata (water ver.)
- UVa 621 Secret Research (water ver.)
- UVa 11044 Searching for Nessy (water ver.)
- 人人笔试题
- 文件系统和数据库系统的区别
- 研究 android apk安装卸载等 产生的 系统广播
- POJ Prime Test
- 不好好读书,将来连表都不认识
- UVa 10019 Funny Encryption Method (water ver.)
- 【MZ】hdu 2243 AC自动机 + 矩阵加速
- C++编译和链接详解
- cocos2dx左下角三行数值意义\去掉
- Android 抽屉效果实现
- n进制转换
- TMS32C64X DSP引起cache miss 的三种情况以及Cache Coherence一致性的解决办法
- C++ primer 笔记
- MD5加密函数