(SPOJ) 11762 - Poodle - Solução

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

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.takeInput();
       
        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 takeInput() throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        double numDocumentos = leitor(br);
        double resultadosPorPagina = leitor(br);
       
        while (numDocumentos != 0 || resultadosPorPagina != 0) {
            int resultadoDivisao = (int)Math.ceil(numDocumentos/resultadosPorPagina);
           
            int limite = resultadoDivisao-6;
            bw.write("Poo");
            if (resultadoDivisao >= 6 && resultadoDivisao <= 20) {
                for (int i = 0; i < limite; i++) {
                    bw.write("o");
                }
            }
            else if (resultadoDivisao > 20) {
                bw.write("oooooooooooooo");
            }
            bw.write("dle\n");
           
            numDocumentos = leitor(br);
            resultadosPorPagina = leitor(br);
        }
       
        bw.flush();
        bw.close();
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução