(SPOJ) 20004 - Campeonato - 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;
        int sinal = 1;
        while (true) {
            n = br.read();
            if (n >= '0' && n <= '9') break;
            if (n == '-') sinal = -1;
            if (n == '+') sinal = 1;
        }
        while (true) {
            resp = resp*10 + n-'0';
            n = br.read();
            if (n < '0' || n > '9') break;
        }

        return resp*sinal;
    }
   
    void processa() throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        int[] cormengo = new int[3];
        int[] flaminthians = new int[3];
       
        for (int i = 0; i < 3; i++) {
            cormengo[i] = leitor(br);
        }
       
        for (int i = 0; i < 3; i++) {
            flaminthians[i] = leitor(br);
        }

        int pontosC = (cormengo[0] * 3) + cormengo[1];
        int pontosF = (flaminthians[0] * 3) + flaminthians[1];
       
        if (pontosC == pontosF) {
            if (cormengo[2] > flaminthians[2]) {
                bw.write("C\n");
            }
            else if (cormengo[2] < flaminthians[2]) {
                bw.write("F\n");
            }
            else {
                bw.write("=\n");
            }
        }
        else if (pontosC > pontosF) {
            bw.write("C\n");
        }
        else {
            bw.write("F\n");
        }
                                  
        bw.flush();
        bw.close();           
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução