Decode the Mad man
|
The Problem
Once in BUET, an old professor had gone completely mad. He started talking with some peculiar words. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble. There was no way left to keep that man working in university. Suddenly a student (definitely he was a registered author at UVA ACM Chapter and hold a good rank on 24 hour-Online Judge) created a program that was able to decode that professor’s speech. After his invention, everyone got comfort again and that old teacher started his everyday works as before.
So, if you ever visit BUET and see a teacher talking with a microphone, which is connected to a IBM computer equipped with a voice recognition software and students are taking their lecture from the computer screen, don’t get thundered! Because now your job is to write the same program which can decode that mad teacher's speech!
The Input
The input file will contain only one test case i.e. the encoded message.The test case consists of one or more words.
The Output
For the given test case, print a line containing the decoded words. However, it is not so hard task to replace each letter or punctuation symbol by the two immediately to its left alphabet on your standard keyboard.
Sample Input
k[r dyt I[o
Sample Output
how are you
解法: 打表對照
import java.util.*; public class UVA10222 { public static void main(String[] args) { String board = "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./"; Scanner sc = new Scanner(System.in); int t; while (sc.hasNext()) { String word = sc.nextLine().toLowerCase(); for (int i = 0; i < word.length(); i++) { t = board.indexOf(word.charAt(i)); if (t != -1) { System.out.print(board.charAt(t - 2)); } else { System.out.print(word.charAt(i)); } } System.out.println(); } } }
留言
張貼留言