encryption program


Submit solution

Points: 20
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

題目說明

<1111檢定考題>
一個簡單的保密方法,就是將訊息依一定的規則重新排列。
現在小明想將訊息依下圖環狀方式排列,中間環心部份保持空白,然後將訊息依序放入同心環狀中。最後,依列由上至下輸出。
11115
111152

輸入

從鍵盤輸入一串文字訊息

輸出

經上述方式加密後,由螢幕輸出加密後的結果。

sample input & output

111153


Comments


  • 0
    scu11113003  commented on March 21, 2024, 6:47 p.m.

    package d_0_1_;

    import java.util.Arrays; import java.util.Scanner;

    public class _encryption {

    public static void main(String[] args) {
    
    
    
        String  y[][] = new String [7][7];
    
        Scanner scan = new Scanner(System.in);
    
        String a = scan.nextLine();
    
        for(int i = 0; i<a.length();i++){
    
            int k[] = search(i);
    
            String kk = "";
    
            char z = a.charAt(i);
    
            kk+=z;
    
            y[k[0]][k[1]] = kk;
    
        }
    
        for(int i = 0 ; i<y.length;i++){
    
            int aa[] = new int[y.length];
    
            for(int j = 0 ; j<aa.length; j++){
    
                if(y[i][j]==null){
                    System.out.print(" ");
                }else{
    
                    System.out.print(y[i][j]);
                }
    
    
    
            }
    
            System.out.println("");
        }
    
    
    }
    
    public static int[] search(int ta){
    
        int x[][] ={
                {31, 32, 33, 34, 35, 36, 37},
                {30, 13, 14, 15, 16, 17, 38},
                {29, 12, 3, 4, 5, 18, 39},
                {28, 11, 2, 0, 6, 19, 40},
                {27, 10, 1, 8, 7, 20, 41},
                {26, 9, 24, 23, 22, 21, 42},
                {25, 48, 47, 46, 45, 44, 43}
    
        };
    
        int p[] = new int[2];
    
        for(int i = 0 ; i<x.length;i++){
    
            int aa[] = new int[x.length];
    
            for(int j = 0 ; j<aa.length; j++){
    
                if(x[i][j]==ta+1){
    
                    p[0] = i;
                    p[1] = j;
                }
            }
        }
    
        return p;
    
    
    }

    }


  • 0
    scu10156153  commented on Jan. 12, 2024, 9:37 p.m.

    這題有解嗎