Pages

Monday 8 October 2012

UVA - 10222 - Decode the Mad man

 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer("");
        String m="";
        ArrayList<Character> arr=new ArrayList<Character>();
        String lol="qwertyuiop[]asdfghjkl;'zxcvbnm,./";
        for(int i=0;i<lol.length();i++){
            arr.add(lol.charAt(i));
        }
        while ((m=br.readLine())!=null) {
                StringBuilder temp=new StringBuilder("");
                for(int i=0;i<m.length();i++){
                    if(m.charAt(i)!=' '){
                        char temp2=Character.toLowerCase(m.charAt(i));
                        int index=arr.indexOf(temp2);
                        temp.append(arr.get(index-2));
                    }else if(m.charAt(i)==' '){
                        temp.append(' ');
                    }
                }
                sb.append(temp).append("\n");
        }
        System.out.print(sb);
    }
}

No comments:

Post a Comment