# UVA 10019 Funny Encryption Method ## 題目連結 [UVA 10019](https://vjudge.net/problem/UVA-10019) ### 題目內容 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 : X~1~ = 265 (decimal) 3. Convert the decimal interpretation of N to its binary representation : X~1~ = 100001001 (binary) 4. Let b1 be equal to the number of 1’s in this binary representation : b~1~ = 3 5. Interpret N as a Hexadecimal number : X~2~ = 265 (hexadecimal) 6. Convert the hexadecimal interpretation of N to its binary representation : X~2~ = 1001100101 7. Let b~2~ be equal to the number of 1’s in the last binary representation : b~2~ = 5 8. The encryption is the result of M xor (b~1~ ∗ b~2~) : 265 xor (3*5) = 262 This student failed Computational Organization, thats 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. You have to write a program that read a Number and give as output the number b~1~ and b~2~ ### 輸入限制 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. ### 輸出限制 You will have to output N lines, each containing the number b~1~ and b~2~ in that order, separated by one space corresponding to that lines number to crypt ### 解題思路 1.cot是算10進制轉2進制中1的數量 2.cnt是算16進制轉2進制所有1的數量 ### 程式碼 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ int kase; cin>>kase; while(kase--){ int n; cin>>n; int cot=0,cnt=0; for(int i=n;i>0;i/=2){ cot+=i%2; } while(n!=0){ int temp=n%10; for(int i=temp;i>0;i/=2){ cnt+=i%2; } n/=10; } cout<<cot<<" "<<cnt<<endl; } } ``` ## 測資 ### Sample input 3 265 111 1234 ### Sample output 3 5 6 3 5 5 ## 中文題目連結 [zerojudge e545](https://zerojudge.tw/ShowProblem?problemid=e545)