ZOJ-1799

来源:互联网 发布:设有一个二维数组a m n 编辑:程序博客网 时间:2024/06/05 17:28

这题其实挺简单。。还做了好久,逻辑思维不大行啊,要多练练

import java.util.Scanner;public class Main{public static void main(String[] args){Scanner sc = new Scanner(System.in);while (true){String key = sc.nextLine().trim();if ("THEEND".equals(key))break;String ciphertext = sc.nextLine().trim();int rows = ciphertext.length() / key.length();char[][] plain = new char[rows][key.length()];int[] orders = getOrder(key);for (int i = 0; i < key.length(); i++){for (int j = 0; j < rows; j++){plain[j][i] = ciphertext.charAt(rows * (orders[i] - 1) + j);}}for (char[] cc : plain){for (char ccc : cc)System.out.print(ccc);}System.out.println();}}static int[] getOrder(String s){char[] chars = s.toCharArray();int[] orders = new int[chars.length];for (int i = 0; i < chars.length; i++){int order = 1;for (int j = 0; j < chars.length; j++){if (j < i){if (chars[i] >= chars[j])order++;}else{if (chars[i] > chars[j])order++;}}orders[i] = order;}return orders;}}


0 0