(SPOJ) 19959 - Peça Perdida - 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);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int qtePecas = leitor(br);
int[] vetor = new int[qtePecas+1];
int numero;
for (int i = 0; i < qtePecas-1; i++) {
numero = leitor(br);
vetor[numero] = 1;
}
boolean achou = false;
numero = 0;
while (!achou) {
numero++;
if (vetor[numero] == 0) {
achou = true;
}
}
System.out.println(numero);
return;
}
}
import java.util.*;
class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
Main processando = new Main();
processando.processa();
System.exit(0);
}
static int leitor(BufferedReader br) throws NumberFormatException, IOException {
int n;
int resp = 0;
while (true) {
n = br.read();
if (n >= '0' && n <= '9') break;
}
while (true) {
resp = resp*10 + n-'0';
n = br.read();
if (n < '0' || n > '9') break;
}
return resp;
}
void processa() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int qtePecas = leitor(br);
int[] vetor = new int[qtePecas+1];
int numero;
for (int i = 0; i < qtePecas-1; i++) {
numero = leitor(br);
vetor[numero] = 1;
}
boolean achou = false;
numero = 0;
while (!achou) {
numero++;
if (vetor[numero] == 0) {
achou = true;
}
}
System.out.println(numero);
return;
}
}
Comments
Post a Comment