题目地址:http://acm.sau.edu.cn/JudgeOnline/problem.php?cid=1002&pid=0
问题 A: Decryption
时间限制: 1 Sec 内存限制: 32 MB提交: 271 解决: 102
题目描述
Little A often receives some encrypted files, of which are all encrypted into 4-length integer (base 10), now he want to decrypt these files.
The roles of decrypting this file are as follows:
1. Translation all the 4-length integers into new numbers base 16.
2. Change the figures into characters as 0 to A, 1 to B, 2 to C…
For example: 2014(base 10) -> 7de(base 16) -> Hde输入
There are several test cases.
For each test case, first line contains a positive integer N (N<=100), followed by N 4-length integers.
If N=0, stop read in.
输出
For each test case, output the information after decrypting. The output of one test case occupied exactly one line.
样例输入
3
1111 1987 6597
4
1485 1000 5987 4444
4
9999 9785 4737 19860
样例输出
EFHHcDBJcF
FcdDeIBHGDBBFc
CHAfCGDJBCIBHcC
提示
/***********************************
*
* acm : hustoj-1010
*
* title: Decryption
*
* time : 2014.4.28
*
***********************************/
//考察10进制转化为16进制
#include <stdio.h>
int main()
{
int n;
int a;
int i;
void D_X(int a); //十进制转换为十六进制
while (~scanf("%d", &n) && n!=0)
{
for (i=0; i<n; i++)
{
scanf("%d", &a);
D_X(a);
}
printf("\n");
}
return 0;
}
void D_X(int a)
{
int x[4]; //十六进制
int i = 0;
int j;
char c;
while (a != 0)
{
x[i] = a % 16;
a = a / 16;
i++;
}
for (j=i-1; j>=0; j--)
{
switch (x[j])
{
case 0: c = 'A';break;
case 1: c = 'B';break;
case 2: c = 'C';break;
case 3: c = 'D';break;
case 4: c = 'E';break;
case 5: c = 'F';break;
case 6: c = 'G';break;
case 7: c = 'H';break;
case 8: c = 'I';break;
case 9: c = 'J';break;
case 10: c = 'a';break;
case 11: c = 'b';break;
case 12: c = 'c';break;
case 13: c = 'd';break;
case 14: c = 'e';break;
case 15: c = 'f';break;
}
printf("%c", c);
}
}