数组-14. 数字加密

数组-14. 数字加密(15)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
陈建海(浙江大学)

输入一个四位数,将其加密后输出。方法是将该数每一位上的数字加9,然后除以10取余,做为该位上的新数字,最后将千位和十位上的数字互换,百位和个位上的数字互换,组成加密后的新四位数。例如输入1257,经过加9取余后得到新数字0146,再经过两次换位后得到4601。

输入格式:

输入在一行中给出一个四位的整数x,即要求被加密的数。

输出格式:

在一行中按照格式“The encrypted number is V”输出加密后得到的新数V。

输入样例:
1257
输出样例:
The encrypted number is 4601
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<stdlib.h>
 4 #include<string.h>
 5 int main()
 6 {
 7     char temp, a[5];
 8     int i;
 9     gets(a);
10     for(i = 0; i < 4; i++)
11         a[i] = (a[i] - '0' + 9) % 10 + '0';
12     temp = a[0];
13     a[0] = a[2];
14     a[2] = temp;
15     temp = a[1];
16     a[1] = a[3];
17     a[3] = temp;
18     printf("The encrypted number is %s
", a);
19     return 0;
20 }
原文地址:https://www.cnblogs.com/yomman/p/4239986.html