Description
儒略?凯撒生活在充满危险和阴谋的年代,而其中最艰难的状况莫过于求得生存。于是他发明了最早的密码系统之一,用于军队的消息传递。?Input
最多不超过100个数据集组成,每个数据集之间不会有空行,每个数据集由3部分组成:?? 1. 起始行:START
?? 2. 密码消息:由1到200个字符组成一行,表示凯撒发出的一条消息.
?? 3. 结束行:END
Output
每个数据集对应一行,是凯撒的原始消息。Sample Input
START NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX END START N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ END START IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ END ENDOFINPUT
Sample Output
IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME DANGER KNOWS FULL WELL THAT CAESAR IS MORE DANGEROUS THAN HE
?
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void printPass(ArrayList<String> password) { for (int i = 0; i < password.size(); i++) { if ("START".equalsIgnoreCase(password.get(i)) || "END".equalsIgnoreCase(password.get(i))) { System.out.print(""); } else { System.out.println(translate(password.get(i))); } } } public static String translate(String password) { char[] ch = password.toCharArray(); // A 65 V86 U 85 Z 90 for (int i = 0; i < ch.length; i++) { if (ch[i]>='A'&&ch[i]<='Z') { if ((char) (ch[i] - 5) < 'A') { ch[i] = (char) (ch[i] + 21); } else { ch[i] = (char) (ch[i] - 5); } } } return new String(ch); } public static void main(String[] args) { Scanner cin = new Scanner(System.in); String password = ""; ArrayList<String> pass = new ArrayList<String>(); while (cin.hasNext()) { password = cin.nextLine(); if ("ENDOFINPUT".equalsIgnoreCase(password)) { printPass(pass); } else { pass.add(password); } } } }
?
注:在ACM提交Code的时候,类名必须为Main,否则编译不通过.
?