(URI) Par ou Ímpar - Solução

import java.io.*;

class Main {
   
static int reader(BufferedReader br) throws NumberFormatException, IOException {
       int n;
       int ans = 0;
       int signal = 1;


       while (true) {
           n = br.read();
           if (n >= '0' && n <= '9') {

               break;
           }
           if (n == '-')
{
               signal = -1;
           }
           if (n == '+')
{
               signal = 1;
           }

       }
       while (true) {
          
ans = ans*10 + n-'0';
           n = br.read();
           if (n < '0' || n > '9')
{
               break;
           }       
       }

       return
ans*signal;
    }


    public void processa() throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
       
        int numTestCases =
reader(br);

        for (int i = 0; i < numTestCases; i++) {
            int num =
reader(br);
            if (num == 0) {
                bw.write("NULL\n");
            }       
            else if (num > 0) {
                if (num%2 == 0) {
                    bw.write("EVEN POSITIVE\n");
                }
                else {
                    bw.write("ODD POSITIVE\n");
                }
            }
            else { // if (num < 0)
                if (num%2 == 0) {
                    bw.write("EVEN NEGATIVE\n");
                }
                else {
                    bw.write("ODD NEGATIVE\n");
                }
            }
        }
       
        bw.flush();
        bw.close();

        return;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.processa();
       
        System.exit(0);
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução