Created
December 5, 2011 07:35
-
-
Save mojaie/1432722 to your computer and use it in GitHub Desktop.
AOJ:0017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner scn = new Scanner(System.in); | |
while (scn.hasNext()) { | |
String str = scn.nextLine(); | |
int len = str.length(); | |
a: | |
while (true) { | |
String nstr = new String(); | |
for (int i = 0; i < len; i++) { | |
int n = str.charAt(i); //アスキーコードに変換 | |
if (n > 96 && n < 122) { | |
n = n + 1; //次のアルファベット | |
} else if (n == 122) { | |
n = 97; //zならaに戻る | |
} | |
nstr = nstr + (char)n; //文字に変換 | |
} | |
str = nstr; | |
String[] words = str.split(" "); | |
for (int i = 0; i < words.length; i++) { | |
//単語末尾のピリオドを除去 | |
if (words[i].charAt(words[i].length() - 1) == '.') { | |
words[i] = words[i].substring(0, words[i].length() - 2); | |
} | |
//the,this,thatがあれば復号完了 | |
if (words[i].equals("the") || words[i].equals("this") || | |
words[i].equals("that")) break a; | |
} | |
} | |
System.out.println(str); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment