数组-14. 数字加密

 1 /*
 2  * Main.c
 3  * E14-数组-14. 数字加密
 4  *  Created on: 2014年8月25日
 5  *      Author: Boomkeeper
 6  ********测试通过*******
 7  */
 8 
 9 #include <stdio.h>
10 
11 int main(void) {
12 
13     int in;
14     int num[5];
15 
16     scanf("%4d", &in);
17 
18     //拆分4位数的各位数
19     int i = 3;
20     while (i >= 0) {
21         num[i] = in % 10;
22 //        printf("拆分:%d\n", num[i]);
23         in /= 10;
24         i--;
25     }
26     //每一位上的数字加9,然后除以10取余
27     for (i = 0; i < 4; i++) {
28         num[i] = (num[i] + 9) % 10;
29 //        printf("+9 = %d\n",num[i]);
30     }
31     //千位和十位上的数字互换,百位和个位上的数字互换
32     int temp;
33     temp = num[0];
34     num[0] = num[2];
35     num[2] = temp;
36 
37     temp = num[1];
38     num[1] = num[3];
39     num[3] = temp;
40 
41     //输出结果
42     printf("The encrypted number is ");
43     for (i = 0; i < 4; i++)
44         printf("%d", num[i]);
45     printf("\n");
46     return 0;
47 }

 

题目链接:

http://pat.zju.edu.cn/contests/basic-programming/%E6%95%B0%E7%BB%84-14

 

 

.

posted @ 2014-08-25 22:52  Boomkeeper  Views(260)  Comments(0Edit  收藏  举报
最好的流量统计 网站流量计数器