zoukankan      html  css  js  c++  java
  • 数组-14. 数字加密(15)

    输入一个四位数,将其加密后输出。方法是将该数每一位上的数字加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 }
  • 相关阅读:
    MIUI(Android)使用Webview上传文件
    使用EntityFramework中DbSet.Set(Type entityType)方法碰到的问题
    Web文件管理:elFinder.Net(支持FTP)
    ASP.NET 根据现有动态页面生成静态Html
    LaTeX学习
    Java Integer剖析
    20140711 loop
    20140711 eat
    20140711 set
    20140710 loop
  • 原文地址:https://www.cnblogs.com/ligen/p/4279234.html
Copyright © 2011-2022 走看看