(UVA) 10082 - WERTYU - Solução

import java.io.*;
import java.util.*;
import java.lang.Math;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.takeInput();
       
        System.exit(0);
    }
   
    void takeInput() throws NumberFormatException, IOException {
        String line = "";

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        Map<Character, Character> teclado = new TreeMap<Character, Character>();
       
        teclado.put('1', '`');
        teclado.put('2', '1');
        teclado.put('3', '2');
        teclado.put('4', '3');
        teclado.put('5', '4');
        teclado.put('6', '5');
        teclado.put('7', '6');
        teclado.put('8', '7');
        teclado.put('9', '8');
        teclado.put('0', '9');
        teclado.put('-', '0');
        teclado.put('=', '-');
        teclado.put('W', 'Q');
        teclado.put('E', 'W');
        teclado.put('R', 'E');
        teclado.put('T', 'R');
        teclado.put('Y', 'T');
        teclado.put('U', 'Y');
        teclado.put('I', 'U');
        teclado.put('O', 'I');
        teclado.put('P', 'O');
        teclado.put('[', 'P');
        teclado.put(']', '[');
        teclado.put('\\', ']');
        teclado.put('S', 'A');
        teclado.put('D', 'S');
        teclado.put('F', 'D');
        teclado.put('G', 'F');
        teclado.put('H', 'G');
        teclado.put('J', 'H');
        teclado.put('K', 'J');
        teclado.put('L', 'K');
        teclado.put(';', 'L');
        teclado.put('\'', ';');
        teclado.put('X', 'Z');
        teclado.put('C', 'X');
        teclado.put('V', 'C');
        teclado.put('B', 'V');
        teclado.put('N', 'B');
        teclado.put('M', 'N');
        teclado.put(',', 'M');
        teclado.put('.', ',');
        teclado.put('/', '.');
        teclado.put(' ', ' ');
       
        while ((line = br.readLine()) != null) {
            Integer tamanho;       
       
            ArrayList<Character> arrayLinha = new ArrayList<Character>();
           
            tamanho = line.length();
            Integer i;
            Integer j;
           
            for (i = 0; i < tamanho; i++) {
                arrayLinha.add(i, line.charAt(i));
            }
           
            ArrayList<Character> key = new ArrayList<Character>();
            ArrayList<Character> value = new ArrayList<Character>();
           
            Integer index = 0;       
            for (Map.Entry<Character, Character> chave: teclado.entrySet()) {
                key.add(index, chave.getKey());
                value.add(index, chave.getValue());
                index++;
            }
           
            tamanho = arrayLinha.size();
            Integer tamanhoMapa = key.size();
           
            for (i = 0; i < tamanho; i++) {
                for (j = 0; j < tamanhoMapa; j++) {
                    if (arrayLinha.get(i) == key.get(j)) {
                        System.out.print(value.get(j));
                        break;
                    }
                }
            }
           
            System.out.println();
          
        }
             
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução