码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-02-07 20:20:35      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

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

输入格式:

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

输出格式:

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

输入样例:

1257

输出样例:

The encrypted number is 4601

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <math.h>
 4 #include <string.h>
 5 #include <stdlib.h>
 6 
 7 using namespace::std; 
 8 
 9 int main(){
10   
11       int n;
12       scanf("%d",&n);
13       int a[4]={0};
14       int temp=n;
15       a[3]=temp%10;
16       int i=2;
17       while((temp=temp/10)!=0)
18       {
19           a[i]=temp%10;
20           i--;
21       }
22      for(i=0;i<4;i++)
23      {
24          a[i]=(a[i]+9)%10;
25      }
26      temp=a[3];
27      a[3]=a[1];
28      a[1]=temp;
29      temp=a[2];
30      a[2]=a[0];
31      a[0]=temp;
32      printf("The encrypted number is ");
33      for(i=0;i<4;i++)
34      {
35          printf("%d",a[i]);
36      }     
37       return 0;
38 }

 

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

标签:

原文地址:http://www.cnblogs.com/ligen/p/4279234.html

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