码迷,mamicode.com
首页 > 其他好文 > 详细

数组-14. 数字加密

时间:2014-08-26 00:13:45      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   2014   

 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

 

 

.

数组-14. 数字加密

标签:style   blog   http   color   os   io   for   ar   2014   

原文地址:http://www.cnblogs.com/boomkeeper/p/E14.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!