数字加密

数字加密

发布时间: 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);
	else
		printf("The encrypted number is %d",-ans);
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值