zoukankan      html  css  js  c++  java
  • 【程序48】

    题目:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三位交换。

    
    import java.util.*;
    
    public class lianxi48   { 
    
        public static void main(String args[]) { 
    
        Scanner s = new Scanner(System.in);
    
        int num=0,temp;
    
        do{
    
            System.out.print("请输入一个4位正整数:");
    
            num = s.nextInt();
    
        }while (num<1000||num>9999); 
    
        int a[]=new int[4]; 
    
        a[0] = num/1000; //取千位的数字 
    
        a[1] = (num/100)%10; //取百位的数字 
    
        a[2] = (num/10)%10; //取十位的数字 
    
        a[3] = num%10; //取个位的数字 
    
        for(int j=0;j<4;j++) 
    
        { 
    
            a[j]+=5; 
    
            a[j]%=10; 
    
        } 
    
        for(int j=0;j<=1;j++) 
    
        { 
    
            temp = a[j]; 
    
            a[j] = a[3-j]; 
    
            a[3-j] =temp; 
    
        } 
    
        System.out.print("加密后的数字为:"); 
    
        for(int j=0;j<4;j++) 
    
            System.out.print(a[j]); 
    
        } 
    
    }
  • 相关阅读:
    动态内存Treap
    最大流Dinic
    图的遍历
    Aho_Corasick自动机(AC自动机)
    邻接表
    COJ 3007 Mr.Yang的小助手
    COJ 0601&0602 动态规划(二)及加强
    Codeforces 603A Alternative Thinking
    HDU 2222 Keywords Search
    codeforce--600D
  • 原文地址:https://www.cnblogs.com/yuyu666/p/9840259.html
Copyright © 2011-2022 走看看