(URI) Mergulho - Solução

import java.io.*;
import java.util.*;

class Main  {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String linha;
       
        while ((linha = br.readLine()) != null) {
            StringTokenizer tokenizer = new StringTokenizer(linha);
            int numVoluntarios = Integer.parseInt(tokenizer.nextToken());
            int retornaram = Integer.parseInt(tokenizer.nextToken());           
            
            int[] listaPresenca = new int[numVoluntarios];         
            for (int i = 0; i < retornaram; i++) {
                int identificador = leitor(br);
                listaPresenca[identificador-1] = 1;
            }
           
            boolean todosVoltaram = true;
            for (int i = 0; i < numVoluntarios; i++) {
                if (listaPresenca[i] == 0) {
                    bw.write((i+1) + " ");
                    todosVoltaram = false;
                }
            }
                   
            if (todosVoltaram) {
                bw.write("*");
            }
           
            bw.newLine();
        }
       
        bw.flush();
        bw.close();
    }

    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;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução