密码字母:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
原文字母:V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
输入描述:
输入包括多组数据,每组数据一行,为收到的密文。 密文仅有空格和大写字母组成。
输出描述:
对应每一组数据,输出解密后的明文
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//密码字母
String str2 = "VWXYZABCDEFGHIJKLMNOPQRSTU";//原文字母
char[] arr = new char[300];
for(int i = 0;i<str1.length();i++){
arr[str1.charAt(i)] = str2.charAt(i);
}
String input = sc.nextLine();
String result = "";
for(int j = 0;j<input.length();j++){
if(input.charAt(j) == ' '){
result = result + " ";
}else{
result = result + arr[input.charAt(j)];
}
}
System.out.println(result);
}
}
}