(SPOJ) 2280 - Encontre o telefone - Solução 1
Solução mais eficiente.
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 {
int[] vetor = new int[91];
vetor[(int)'A'] = '2';
vetor[(int)'B'] = '2';
vetor[(int)'C'] = '2';
vetor[(int)'D'] = '3';
vetor[(int)'E'] = '3';
vetor[(int)'F'] = '3';
vetor[(int)'G'] = '4';
vetor[(int)'H'] = '4';
vetor[(int)'I'] = '4';
vetor[(int)'J'] = '5';
vetor[(int)'K'] = '5';
vetor[(int)'L'] = '5';
vetor[(int)'M'] = '6';
vetor[(int)'N'] = '6';
vetor[(int)'O'] = '6';
vetor[(int)'P'] = '7';
vetor[(int)'Q'] = '7';
vetor[(int)'R'] = '7';
vetor[(int)'S'] = '7';
vetor[(int)'T'] = '8';
vetor[(int)'U'] = '8';
vetor[(int)'V'] = '8';
vetor[(int)'X'] = '9';
vetor[(int)'Y'] = '9';
vetor[(int)'W'] = '9';
vetor[(int)'Z'] = '9';
vetor[(int)'0'] = '0';
vetor[(int)'1'] = '1';
vetor[(int)'-'] = '-';
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while((line = br.readLine()) != null) {
for (int i = 0; i < line.length(); i++) {
bw.write(vetor[(int)line.charAt(i)]);
}
bw.write("\n");
}
bw.flush();
bw.close();
return;
}
}
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 {
int[] vetor = new int[91];
vetor[(int)'A'] = '2';
vetor[(int)'B'] = '2';
vetor[(int)'C'] = '2';
vetor[(int)'D'] = '3';
vetor[(int)'E'] = '3';
vetor[(int)'F'] = '3';
vetor[(int)'G'] = '4';
vetor[(int)'H'] = '4';
vetor[(int)'I'] = '4';
vetor[(int)'J'] = '5';
vetor[(int)'K'] = '5';
vetor[(int)'L'] = '5';
vetor[(int)'M'] = '6';
vetor[(int)'N'] = '6';
vetor[(int)'O'] = '6';
vetor[(int)'P'] = '7';
vetor[(int)'Q'] = '7';
vetor[(int)'R'] = '7';
vetor[(int)'S'] = '7';
vetor[(int)'T'] = '8';
vetor[(int)'U'] = '8';
vetor[(int)'V'] = '8';
vetor[(int)'X'] = '9';
vetor[(int)'Y'] = '9';
vetor[(int)'W'] = '9';
vetor[(int)'Z'] = '9';
vetor[(int)'0'] = '0';
vetor[(int)'1'] = '1';
vetor[(int)'-'] = '-';
String line = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
while((line = br.readLine()) != null) {
for (int i = 0; i < line.length(); i++) {
bw.write(vetor[(int)line.charAt(i)]);
}
bw.write("\n");
}
bw.flush();
bw.close();
return;
}
}
Comments
Post a Comment