数字加密

来源:互联网 发布:人人商城分销 源码 编辑:程序博客网 时间:2024/06/06 05:16

数字加密

发布时间: 2015年12月13日 20:31   最后更新: 2015年12月26日 22:54   时间限制: 1000ms   内存限制: 128M

输入一个4位数,将其加密后输出。方法是将该数每一位上的数字加9然后除以10取余,作为该位上的新数字,最后将第一位和第三位的数字互换,第二位和第四位上的数字互换,组成加密后的新数。

请按照这样的格式输出: “The encrypted number is 1234”(不输出引号)

输出时请省略前导0。这意味着如果加密后的数字为0123,你需要输出“The encrypted number is 123”

一个四位整数

输出字符串“The encrypted number is ”加经过加密以后的数字

 复制
1257
The encrypted number is 4601
 复制
1211
The encrypted number is 1
#include<stdio.h>int main(){int i=3,n,tmp,ans=0,an[5],flag=1;scanf("%d",&n);if(n<0){n=-n;flag=0;}while(n){an[i--]=(n%10+9)%10;n/=10;}tmp=an[0];an[0]=an[2];an[2]=tmp;tmp=an[1];an[1]=an[3];an[3]=tmp;ans=an[0]*1000+an[1]*100+an[2]*10+an[3];if(flag)printf("The encrypted number is %d",ans);elseprintf("The encrypted number is %d",-ans);return 0;}



原创粉丝点击