(SPOJ) 19964 - Telefone - Solução
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<Character,Character> traducao = new HashMap<Character,Character>();
traducao.put('A', '2');
traducao.put('B', '2');
traducao.put('C', '2');
traducao.put('D', '3');
traducao.put('E', '3');
traducao.put('F', '3');
traducao.put('G', '4');
traducao.put('H', '4');
traducao.put('I', '4');
traducao.put('J', '5');
traducao.put('K', '5');
traducao.put('L', '5');
traducao.put('M', '6');
traducao.put('N', '6');
traducao.put('O', '6');
traducao.put('P', '7');
traducao.put('Q', '7');
traducao.put('R', '7');
traducao.put('S', '7');
traducao.put('T', '8');
traducao.put('U', '8');
traducao.put('V', '8');
traducao.put('W', '9');
traducao.put('X', '9');
traducao.put('Y', '9');
traducao.put('Z', '9');
traducao.put('1', '1');
traducao.put('2', '2');
traducao.put('3', '3');
traducao.put('4', '4');
traducao.put('5', '5');
traducao.put('6', '6');
traducao.put('7', '7');
traducao.put('8', '8');
traducao.put('9', '9');
traducao.put('0', '0');
traducao.put('#', '#');
traducao.put('*', '*');
traducao.put('-', '-');
String line = br.readLine();
int tamanho = line.length();
for (int i = 0; i < tamanho; i++) {
bw.write(traducao.get(line.charAt(i)));
}
bw.newLine();
bw.flush();
bw.close();
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Map<Character,Character> traducao = new HashMap<Character,Character>();
traducao.put('A', '2');
traducao.put('B', '2');
traducao.put('C', '2');
traducao.put('D', '3');
traducao.put('E', '3');
traducao.put('F', '3');
traducao.put('G', '4');
traducao.put('H', '4');
traducao.put('I', '4');
traducao.put('J', '5');
traducao.put('K', '5');
traducao.put('L', '5');
traducao.put('M', '6');
traducao.put('N', '6');
traducao.put('O', '6');
traducao.put('P', '7');
traducao.put('Q', '7');
traducao.put('R', '7');
traducao.put('S', '7');
traducao.put('T', '8');
traducao.put('U', '8');
traducao.put('V', '8');
traducao.put('W', '9');
traducao.put('X', '9');
traducao.put('Y', '9');
traducao.put('Z', '9');
traducao.put('1', '1');
traducao.put('2', '2');
traducao.put('3', '3');
traducao.put('4', '4');
traducao.put('5', '5');
traducao.put('6', '6');
traducao.put('7', '7');
traducao.put('8', '8');
traducao.put('9', '9');
traducao.put('0', '0');
traducao.put('#', '#');
traducao.put('*', '*');
traducao.put('-', '-');
String line = br.readLine();
int tamanho = line.length();
for (int i = 0; i < tamanho; i++) {
bw.write(traducao.get(line.charAt(i)));
}
bw.newLine();
bw.flush();
bw.close();
return;
}
}
Comments
Post a Comment