URI Problem (Even or Odd) 1074 Solution in Java

URI Problem (Even or Odd) 1074 Solution in Java

URI Problem (Even or Odd) 1074:
Even or Odd is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 10:47:52 PM
 */
public class Uri1074 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n < 10000) {
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                if (x > -10000000 && x < 10000000) {
                    if (x == 0) {
                        System.out.println("NULL");
                    } else if (x % 2 == 0) {
                        if (x > 0) {
                            System.out.println("EVEN POSITIVE");
                        } else {
                            System.out.println("EVEN NEGATIVE");
                        }
                    } else if (x > 0) {
                        System.out.println("ODD POSITIVE");
                    } else {
                        System.out.println("ODD NEGATIVE");
                    }
                }
            }
        }
    }
}
URI Problem (Even Square) 1073 Solution in Java

URI Problem (Even Square) 1073 Solution in Java

URI Problem (Even Square) 1073:
Even Square is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 10:37:29 PM
 */
public class Uri1073 {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n > 5 && n < 2000) {
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 0) {
                    System.out.println(i + "^2" + " = " + (int)Math.pow(i, 2));
                }
            }
        }
    }
}
URI Problem (Interval 2) 1072 Solution in Java

URI Problem (Interval 2) 1072 Solution in Java

URI Problem (Interval 2) 1072:
Interval 2 is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 10:27:14 PM
 */
public class Uri1072 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int in = 0, out = 0;
        if (n < 10000) {
            for (int i = 0; i < n; i++) {
                int value = sc.nextInt();
                if (value > -10000000 && value < 10000000) {
                    if (value >= 10 && value <= 20) {
                        in++;
                    } else {
                        out++;
                    }
                }
            }
            System.out.println(in+" in");
            System.out.println(out+" out");
        }
    }
}
URI Problem (Sum of Consecutive Odd Numbers I) 1071 Solution in Java

URI Problem (Sum of Consecutive Odd Numbers I) 1071 Solution in Java

URI Problem (Sum of Consecutive Odd Numbers I) 1071:
Sum of Consecutive Odd Numbers I is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 9:46:56 PM
 */
public class Uri1071 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x, y, total = 0;
        x = sc.nextInt();
        y = sc.nextInt();
        if (x > y) {
            int temp = x;
            x = y;
            y = temp;
        }
        for (int i = x + 1; i < y; i++) {
            if (i % 2 != 0) {
                total += i;
            }
        }
        System.out.println(total);
    }
}
URI Problem (Six Odd Numbers) 1070 Solution in Java

URI Problem (Six Odd Numbers) 1070 Solution in Java

URI Problem (Six Odd Numbers) 1070:
Six Odd Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 9:36:31 PM
 */
public class Uri1070 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int count = 0;
        if (x > 0) {
            while (count < 6) {
                if (x % 2 != 0) {
                    count++;
                    System.out.println(x);
                }
                x++;
            }

        }
    }
}
URI Problem (Odd Numbers) 1067 Solution in Java

URI Problem (Odd Numbers) 1067 Solution in Java

URI Problem (Odd Numbers) 1067:
Odd Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 9:30:14 PM
 */
public class Uri1067 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x >= 1 && x <= 1000) {
            for (int i = 1; i <= x; i++) {
                if (i % 2 != 0) {
                    System.out.println(i);
                }
            }
        }
    }
}
URI Problem (Even Between five Numbers) 1065 Solution in Java

URI Problem (Even Between five Numbers) 1065 Solution in Java

URI Problem (Even Between five Numbers) 1065:
Even Between five Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 14, 2016
 * @Time   : 9:17:28 PM
 */
public class Uri1065 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int values[] = new int[5];
        int count = 0;
        for (int i = 0; i < values.length; i++) {
            values[i] = sc.nextInt();
            if(values[i]%2==0){
                count++;
            }
        }
        System.out.println(count+" valores pares");
    }
}
URI Problem (Even, Odd, Positive and Negative) 1066 Solution in Java

URI Problem (Even, Odd, Positive and Negative) 1066 Solution in Java

URI Problem (Even, Odd, Positive and Negative) 1066:
Even, Odd, Positive and Negative is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 9:22:14 PM
 */
public class Uri1066 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int values[] = new int[5];
        int pos = 0, neg = 0, even = 0, odd = 0;
        for (int i = 0; i < values.length; i++) {
            values[i] = sc.nextInt();
            if (values[i] > 0) {
                pos++;
            }
            if (values[i] < 0) {
                neg++;
            }
            if (values[i] % 2 == 0) {
                even++;
            } else {
                odd++;
            }
        }
        System.out.println(even + " valor(es) par(es)");
        System.out.println(odd + " valor(es) impar(es)");
        System.out.println(pos + " valor(es) positivo(s)");
        System.out.println(neg + " valor(es) negativo(s)");

    }
}
URI Problem (Positives and Average) 1064 Solution in Java

URI Problem (Positives and Average) 1064 Solution in Java

URI Problem (Positives and Average) 1064:
Positives and Average is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 8:52:04 PM
 */
public class Uri1064 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double values[] = new double[6];
        int count = 0;
        double total = 0;
        for (int i = 0; i < values.length; i++) {
            values[i] = sc.nextDouble();
        }
        if (checkValue(values)) {
            for (int i = 0; i < values.length; i++) {
                if (values[i] > 0) {
                    count++;
                    total += values[i];
                }
            }

            if (count != 0) {
                System.out.println(count + " valores positivos");
                System.out.printf("%.1f\n", (total / count));
            }
        }
    }

    private static boolean checkValue(double x[]) {
        boolean flag = false;
        for (int i = 0; i < x.length; i++) {
            if (x[i] > 0) {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
URI Problem (Event Time) 1061 Solution in Java

URI Problem (Event Time) 1061 Solution in Java

URI Problem (Event Time) 1061:
Event Time is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 7:32:12 PM
 */
public class Uri1061 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s_day, s_time, e_day, e_time;
        String s_split_time[], e_split_time[];
        int start_day, end_day, start_hour, end_hour, start_minute, end_minute,
                start_second, end_second, day = 0, hour = 0, minute = 0, second = 0;

        s_day = sc.nextLine();
        s_time = sc.nextLine();
        e_day = sc.nextLine();
        e_time = sc.nextLine();

        start_day = toInt(s_day);
        end_day = toInt(e_day);

        s_split_time = s_time.split(" : ");
        e_split_time = e_time.split(" : ");

        start_hour = stoInt(s_split_time[0]);
        start_minute = stoInt(s_split_time[1]);
        start_second = stoInt(s_split_time[2]);

        end_hour = stoInt(e_split_time[0]);
        end_minute = stoInt(e_split_time[1]);
        end_second = stoInt(e_split_time[2]);

        //second:
        if (end_second >= start_second) {
            second = end_second - start_second;
        } else {
            second = end_second - start_second + 60;
            end_minute = end_minute - 1;
        }
        //minute:
        if (end_minute >= start_minute) {
            minute = end_minute - start_minute;
        } else {
            minute = end_minute - start_minute + 60;
            end_hour = end_hour - 1;
        }
        //hour:
        if (end_hour >= start_hour) {
            hour = end_hour - start_hour;
        } else {
            hour = end_hour - start_hour + 24;
            end_day = end_day - 1;
        }
        //day:
        if (end_day >= start_day) {
            day = end_day - start_day;
        }
        System.out.println(day + " dia(s)");
        System.out.println(hour + " hora(s)");
        System.out.println(minute + " minuto(s)");
        System.out.println(second + " segundo(s)");
    }

    private static Integer toInt(String start_day) {
        return Integer.valueOf(start_day.substring(4).trim());
    }

    private static Integer stoInt(String start_day) {
        return Integer.valueOf(start_day.trim());
    }
}
URI Problem (Positive Numbers) 1060 Solution in Java

URI Problem (Positive Numbers) 1060 Solution in Java

URI Problem (Positive Numbers) 1060:
Positive Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 7:19:01 PM
 */
public class Uri1060 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double values[] = new double[6];
        int count = 0;
        for (int i = 0; i < values.length; i++) {
            values[i] = sc.nextDouble();
            if(values[i]>0){
                count++;
            }
        }
        System.out.println(count+" valores positivos");
    }

}
URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Even Numbers) 1059 Solution in Java

URI Problem (Even Numbers) 1059:
Even Numbers is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @E-mail : [email protected]
 * @Date : Oct 14, 2016
 * @Time : 7:13:58 PM
 */
public class Uri1059 {

    public static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
            }
        }
    }
}
URI Problem (Month) 1052 Solution in Java

URI Problem (Month) 1052 Solution in Java

URI Problem (Month) 1052:
Month is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 14, 2016
 * @Time   : 6:59:52 PM
 */
public class Uri1052 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String months[] = {"January","February","March","April","May","June",
            "July","August","September","October","November","December"};
        int month = sc.nextInt();
        if(month>=1 && month<=12){
            System.out.println(months[month-1]); 
        }
    }
}
URI Problem (Taxes) 1051 Solution in Java

URI Problem (Taxes) 1051 Solution in Java

URI Problem (Taxes) 1051:
Taxes is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 6:03:24 PM
 */
public class Uri1051 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double salary, tax = 0;
        salary = sc.nextDouble();
        if (salary >= 0.0 && salary <= 2000.00) {
            System.out.println("Isento");
        } else if (salary >= 2000.01 && salary <= 3000.00) {
            tax += (salary - 2000.00) * 0.08;
            System.out.printf("R$ %.2f\n", tax);
        } else if (salary >= 3000.01 && salary <= 4500.00) {
            tax += 1000.00 * 0.08;
            tax += (salary - 3000) * 0.18;
            System.out.printf("R$ %.2f\n", tax);
        } else if (salary > 4500.00) {
            tax += 1000.00 * 0.08;
            tax += 1500.00 * 0.18;
            tax += (salary - 4500.00) * 0.28;
            System.out.printf("R$ %.2f\n", tax);
        }
    }
}
URI Problem (DDD) 1050 Solution in Java

URI Problem (DDD) 1050 Solution in Java

URI Problem (DDD) 1050:
DDD is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 5:14:33 PM
 */
public class Uri1050 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number = sc.nextInt();
        switch (number) {
            case 61:
                System.out.println("Brasilia");
                break;
            case 71:
                System.out.println("Salvador");
                break;
            case 11:
                System.out.println("Sao Paulo");
                break;
            case 21:
                System.out.println("Rio de Janeiro");
                break;
            case 32:
                System.out.println("Juiz de Fora");
                break;
            case 19:
                System.out.println("Campinas");
                break;
            case 27:
                System.out.println("Vitoria");
                break;
            case 31:
                System.out.println("Belo Horizonte");
                break;
            default:
                System.out.println("DDD nao cadastrado");
                break;
        }
    }
}
URI Problem (Animal) 1049 Solution in Java

URI Problem (Animal) 1049 Solution in Java

URI Problem (Animal) 1049:
Animal is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date   : Oct 14, 2016
 * @Time   : 4:21:29 PM
 */
public class Uri1049 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String v1,v2,v3;
        v1 = toLowerAndTrim(sc.next());
        v2 = toLowerAndTrim(sc.next());
        v3 = toLowerAndTrim(sc.next());
        if(v1.equalsIgnoreCase("vertebrado")){
            if(v2.equalsIgnoreCase("ave")){
                if(v3.equalsIgnoreCase("carnivoro")){
                    System.out.println("aguia");
                }else if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("pomba");
                }
            }else if(v2.equalsIgnoreCase("mamifero")){
                if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("homem");
                }else if(v3.equalsIgnoreCase("herbivoro")){
                    System.out.println("vaca");
                }
            }
        }else if(v1.equalsIgnoreCase("invertebrado")){
            if(v2.equalsIgnoreCase("inseto")){
                if(v3.equalsIgnoreCase("hematofago")){
                    System.out.println("pulga");
                }else if(v3.equalsIgnoreCase("herbivoro")){
                    System.out.println("lagarta");
                }
            }else if(v2.equalsIgnoreCase("anelideo")){
                if(v3.equalsIgnoreCase("hematofago")){
                    System.out.println("sanguessuga");
                }else if(v3.equalsIgnoreCase("onivoro")){
                    System.out.println("minhoca");
                }
            }
        }
    }

    private static String toLowerAndTrim(String next) {
        return next.trim().toLowerCase();
    }
}
URI Problem (Salary Increase) 1048 Solution in Java

URI Problem (Salary Increase) 1048 Solution in Java

URI Problem (Salary Increase) 1048:
Salary Increase is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 14, 2016
 * @Time : 3:41:23 PM
 */
public class Uri1048 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double salary, new_salary, money_earned;
        int percentage;
        salary = sc.nextDouble();
        if (salary >= 0.00 && salary <= 400.00) {
            percentage = 15;
            calculation_and_print(salary, percentage);
        }else if (salary >= 400.01 && salary <= 800.00) {
            percentage = 12;
            calculation_and_print(salary, percentage);
        }else if (salary >= 800.01 && salary <= 1200.00) {
            percentage = 10;
            calculation_and_print(salary, percentage);
        }else if (salary >= 1200.01 && salary <= 2000.00) {
            percentage = 7;
            calculation_and_print(salary, percentage);
        }else if (salary > 2000.00) {
            percentage = 4;
            calculation_and_print(salary, percentage);
        }
    }

    private static void calculation_and_print(double salary, int percentage) {
        double money_earned;
        double new_salary;
        money_earned = salary * (percentage / 100.00);
        new_salary = salary + money_earned;
        System.out.printf("Novo salario: %.2f\n", new_salary);
        System.out.printf("Reajuste ganho: %.2f\n", money_earned);
        System.out.println("Em percentual: "+ percentage+" %");
    }
}
URI Problem (Game Time with Minutes) 1047 Solution in Java

URI Problem (Game Time with Minutes) 1047 Solution in Java

URI Problem (Game Time with Minutes) 1047:
Game Time with Minutes is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 12, 2016
 * @Time : 2:31:23 PM
 */
public class Uri1047 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int start_hour, start_minute, end_hour, end_minute, hour = 0, minute = 0;
        start_hour = sc.nextInt();
        start_minute = sc.nextInt();
        end_hour = sc.nextInt();
        end_minute = sc.nextInt();
        if (start_hour >= 0 && start_hour <= 24 && end_hour >= 0
                && end_hour <= 24 && start_minute >= 0 && start_minute <= 60
                && end_minute >= 0 && end_minute <= 60) {
            if (end_minute > start_minute) {
                minute = end_minute - start_minute;
            } else if (end_minute < start_minute) {
                minute = end_minute - start_minute + 60;
                end_hour = end_hour - 1;
            }
            if (end_hour >= start_hour) {
                hour = end_hour - start_hour;
            } else if (end_hour < start_hour) {
                hour = end_hour - start_hour + 24;
            }
            if (hour == 0 && minute == 0) {
                hour = 24;
            }
        }
        System.out.println("O JOGO DUROU " + hour + " HORA(S) E " + minute + " MINUTO(S)");
    }
}
URI Problem (Game Time) 1046 Solution in Java

URI Problem (Game Time) 1046 Solution in Java

URI Problem (Game Time) 1046:
Game Time is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 12, 2016
 * @Time : 2:10:33 PM
 */
public class Uri1046 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int start, end, duration = 0;
        start = sc.nextInt();
        end = sc.nextInt();
        if (start <= 24 && end <= 24 && start >= 0 && end >= 0) {
            if (end > start) {
                duration = end - start;
            } else if (end < start || end == start) {
                duration = (end - start) + 24;
            }
            System.out.println("O JOGO DUROU "+duration+" HORA(S)");
        }
    }
}
URI Problem (Triangle Types) 1045 Solution in Java

URI Problem (Triangle Types) 1045 Solution in Java

URI Problem (Triangle Types) 1045:
Triangle Types is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.

import java.util.Scanner;

/**
 * @Author : Muhammad Harun-Or-Roshid
 * @Date : Oct 11, 2016
 * @Time : 3:31:17 PM
 */
public class Uri1045 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a, b, c;
        a = sc.nextDouble();
        b = sc.nextDouble();
        c = sc.nextDouble();
        if (a > 0 && b > 0 && c > 0) {
            double abc[] = sortDecreasing(new double[]{a, b, c});
            a = abc[0];
            b = abc[1];
            c = abc[2];
            //if A ≥ B + C, write the message: NAO FORMA TRIANGULO
            if (a >= (b + c)) {
                System.out.println("NAO FORMA TRIANGULO");
            }
            //if A2 = B2 + C2, write the message: TRIANGULO RETANGULO
            else if ((a * a) == ((b * b) + (c * c))) {
                System.out.println("TRIANGULO RETANGULO");
            }
            //if A2 > B2 + C2, write the message: TRIANGULO OBTUSANGULO
            else if ((a * a) > ((b * b) + (c * c))) {
                System.out.println("TRIANGULO OBTUSANGULO");
            }
            //if A2 < B2 + C2, write the message: TRIANGULO ACUTANGULO
            else if ((a * a) < ((b * b) + (c * c))) {
                System.out.println("TRIANGULO ACUTANGULO");
            }
            
            //if the three sides are the same size, write the message: TRIANGULO EQUILATERO
            if (a == b && b == c  && c==a) {
                System.out.println("TRIANGULO EQUILATERO");
            }
            //if only two sides are the same and the third one is different, write the message: TRIANGULO ISOSCELES
            else if ((a == b && a != c) || (b == c && b != a) || (a == c && a != b)) {
                System.out.println("TRIANGULO ISOSCELES");
            }
        }
    }

    private static double[] sortDecreasing(double[] par) {

        for (int i = 0; i < par.length; i++) {
            for (int j = 0; j < par.length - 1; j++) {
                if (par[j] < par[j + 1]) {
                    double temp = par[j];
                    par[j] = par[j + 1];
                    par[j + 1] = temp;
                }

            }
        }
        return par;
    }
}