2010/02/01

WERTYU

將鍵盤往左移一格

import java.util.HashMap;

public class JAVA {


      public static byte[] cinbuf = new byte[1024];
      
      public static String readLine() {
        int offset = 0;
        int bytedata = -1;
        
        try {

          bytedata = System.in.read();
          while(bytedata!=-1) {
            if(bytedata==10) {
              break;
            } else {
              cinbuf[offset++] = (byte)bytedata;
            }
            bytedata = System.in.read();
          }
        } catch(Exception e) {}
     
        if(offset+bytedata==-1) return null; 
        if(cinbuf[offset-1]=='\r') offset--; 
        return new String(cinbuf,0,offset);
      }
      
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        HashMap<Character, Character> maplist = new HashMap<Character, Character>();
        
        // first row
        maplist.put('1', '`');
        maplist.put('2', '1');
        maplist.put('3', '2');
        maplist.put('4', '3');
        maplist.put('5', '4');
        maplist.put('6', '5');
        maplist.put('7', '6');
        maplist.put('8', '7');
        maplist.put('9', '8');
        maplist.put('0', '9');
        maplist.put('-', '0');
        maplist.put('=', '-');
        
        // second row
        maplist.put('W', 'Q');
        maplist.put('E', 'W');
        maplist.put('R', 'E');
        maplist.put('T', 'R');
        maplist.put('Y', 'T');
        maplist.put('U', 'Y');
        maplist.put('I', 'U');
        maplist.put('O', 'I');
        maplist.put('P', 'O');
        maplist.put('[', 'P');
        maplist.put(']', '[');
        maplist.put('\\', ']');
        
        // third row
        maplist.put('S', 'A');
        maplist.put('D', 'S');
        maplist.put('F', 'D');
        maplist.put('G', 'F');
        maplist.put('H', 'G');
        maplist.put('J', 'H');
        maplist.put('K', 'J');
        maplist.put('L', 'K');
        maplist.put(';', 'L');
        maplist.put('\'', ';');
        
        // forth row
        maplist.put('X', 'Z');
        maplist.put('C', 'X');
        maplist.put('V', 'C');
        maplist.put('B', 'V');
        maplist.put('N', 'B');
        maplist.put('M', 'N');
        maplist.put(',', 'M');
        maplist.put('.', ',');
        maplist.put('/', '.');
        
        // space
        maplist.put(' ', ' ');
        
        String num;
        
        while((num = readLine()) != null) {
                    
            for(int i=0;i<num.length();i++){
                System.out.print(maplist.get(num.charAt(i)));
            }
            
            System.out.println();
        }
    }
}

No comments:

Post a Comment