(SPOJ) 18537 - Corrida - 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));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        int idCharrete1 = leitor(br);
        int distCharrete1 = leitor(br);
        int velocCharrete1 = leitor(br);
       
        int idCharrete2 = leitor(br);
        int distCharrete2 = leitor(br);
        int velocCharrete2 = leitor(br);
       
        float tempoCharrete1 = (float)(distCharrete1 * 60) / (float)(velocCharrete1 * 1000);
        float tempoCharrete2 = (float)(distCharrete2 * 60) / (float)(velocCharrete2 * 1000);
       
        if (tempoCharrete1 < tempoCharrete2) {
            bw.write(idCharrete1 + "\n");
        }
        else {
            bw.write(idCharrete2 + "\n");
        }
                                      
        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