by Muhammad Harun-Or-Roshid | Feb 1, 2019 | Problem Solving, URI
URI Problem (Multiples) 1044:
Multiples 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 10, 2016
* @Time : 11:01:05 PM
*/
public class Uri1044 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b;
a = sc.nextInt();
b = sc.nextInt();
if(b%a==0 || a%b==0){
System.out.println("Sao Multiplos");
}else{
System.out.println("Nao sao Multiplos");
}
}
}
by Muhammad Harun-Or-Roshid | Feb 1, 2019 | Problem Solving, URI
URI Problem (Triangle) 1043:
Triangle 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 10, 2016
* @Time : 10:50:53 PM
*/
public class Uri1043 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a, b, c, perimeter, area_trapezium;
a = sc.nextDouble();
b = sc.nextDouble();
c = sc.nextDouble();
if ((a + b) > c && (b + c) > a && (c + a) > b) {
perimeter = a + b + c;
System.out.printf("Perimetro = %.1f\n", perimeter);
} else {
area_trapezium = ((a + b) / 2) * c;
System.out.printf("Area = %.1f\n", area_trapezium);
}
}
}
by Muhammad Harun-Or-Roshid | Feb 1, 2019 | Problem Solving, URI
URI Problem (Simple Sort) 1042:
Simple Sort is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.
import java.util.Arrays;
import java.util.Scanner;
/**
* @Author : Muhammad Harun-Or-Roshid
* @Date : Oct 10, 2016
* @Time : 10:10:17 PM
*/
public class Uri1042 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a , b , c , t;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
int sort[]={a,b,c};
int temp[]={a,b,c};
Arrays.sort(sort);
for (int i = 0; i < sort.length; i++) {
System.out.println(sort[i]);
}
System.out.println();
for (int i = 0; i < temp.length; i++) {
System.out.println(temp[i]);
}
}
}
by Muhammad Harun-Or-Roshid | Feb 1, 2019 | Problem Solving, URI
URI Problem (Coordinates of a Point) 1041:
Coordinates of a Point 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 10, 2016
* @Time : 9:56:05 PM
*/
public class Uri1041 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x,y;
x = sc.nextDouble();
y = sc.nextDouble();
if(x!=0 && y==0){
System.out.println("Eixo X");
}else if(x==0 && y!=0){
System.out.println("Eixo Y");
}else if(x == 0 && y ==0){
System.out.println("Origem");
}else if(x>0 && y>0){
System.out.println("Q1");
}else if(x<0 && y>0){
System.out.println("Q2");
}else if(x<0 && y<0){
System.out.println("Q3");
}else if(x>0 && y<0){
System.out.println("Q4");
}else{
}
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Average 3) 1040:
Average 3 is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.
import java.text.DecimalFormat;
import java.util.Scanner;
/**
* @Author : Muhammad Harun-Or-Roshid
* @Date : Oct 10, 2016
* @Time : 9:09:13 PM
*/
public class Uri1040 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double n1, n2, n3, n4, n5, average, recalculate;
int a = 2, b = 3, c = 4, d = 1;
n1 = sc.nextDouble();
n2 = sc.nextDouble();
n3 = sc.nextDouble();
n4 = sc.nextDouble();
average = toDouble(((n1 * a) + (n2 * b) + (n3 * c) + (n4 * d)) / (a + b + c + d));
System.out.println("Media: " + average);
if (average >= 7.0) {
System.out.println("Aluno aprovado.");
} else if (average < 5.0) {
System.out.println("Aluno reprovado.");
} else if(average >=5.00 && average <= 6.9){
System.out.println("Aluno em exame.");
n5 = sc.nextDouble();
System.out.println("Nota do exame: " + n5);
recalculate = toDouble((n5 + average) / 2);
if (recalculate >= 5.0) {
System.out.println("Aluno aprovado.");
} else if (recalculate <= 4.9) {
System.out.println("Aluno reprovado.");
}
System.out.println("Media final: " + recalculate);
}
}
private static double toDouble(double x){
DecimalFormat format = new DecimalFormat("#0.0");
return Double.valueOf(format.format(x));
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Snack) 1038:
Snack 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 10, 2016
* @Time : 1:47:37 AM
*/
public class Uri1038 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x,y;
x = sc.nextInt();
y = sc.nextInt();
double price[] = {4.00,4.50,5.00,2.00,1.50};
if(price.length >= x){
System.out.printf("Total: R$ %.2f\n",price[x-1]*y);
}
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Interval) 1037:
Interval 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 10, 2016
* @Time : 1:36:06 AM
*/
public class Uri1037 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x = sc.nextDouble();
if (x >= 0 && x <= 25) {
System.out.println("Intervalo " + "[0,25]");
} else if (x > 25 && x <= 50) {
System.out.println("Intervalo " + "(25,50]");
} else if (x > 50 && x <= 75) {
System.out.println("Intervalo " + "(50,75]");
} else if (x > 75 && x <= 100) {
System.out.println("Intervalo " + "(75,100]");
} else {
System.out.println("Fora de intervalo");
}
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Bhaskara’s Formula) 1036:
Bhaskara’s Formula 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 10, 2016
* @Time : 1:14:36 AM
*/
public class Uri1036 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
double b = sc.nextDouble();
double c = sc.nextDouble();
double x = nonNegative(a, b, c);
double y = nonZero(a);
if (y != 0 && x >= 0) {
double r1 = (-b+Math.sqrt(x))/y;
double r2 = (-b-Math.sqrt(x))/y;
System.out.printf("R1 = %.5f\n",r1);
System.out.printf("R2 = %.5f\n",r2);
} else {
System.out.println("Impossivel calcular");
}
}
private static double nonZero(double a) {
return 2 * a;
}
private static double nonNegative(double a, double b, double c) {
return Math.pow(b, 2) - (4 * a * c);
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Selection Test 1) 1035:
Selection Test 1 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
* @E-mail : [email protected]
* @Date : Oct 10, 2016
* @Time : 12:41:48 AM
*/
public class Uri1035 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c, d;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
d = sc.nextInt();
if (compareTo(b, c) && compareTo(d, a) && compareTo(sum(c, d), sum(a, b))
&& checkPositive(c) && checkPositive(d) && checkEven(a)) {
System.out.println("Valores aceitos");
} else {
System.out.println("Valores nao aceitos");
}
}
/**
*
* @param x given value
* @param y compare value
* @return true or false
*/
private static boolean compareTo(int x, int y) {
return x > y;
}
/**
*
* @param x
* @param y
* @return sum of x and y
*/
private static int sum(int x, int y) {
return x + y;
}
/**
*
* @param x check positive value
* @return true or false
*/
private static boolean checkPositive(int x) {
return x > 0;
}
/**
*
* @param x <i>check even</i>
* @return true or false
*/
private static boolean checkEven(int x) {
return x % 2 == 0;
}
}
by Muhammad Harun-Or-Roshid | Jan 31, 2019 | Problem Solving, URI
URI Problem (Banknotes and Coins) 1021:
Banknotes and Coins is a basic problem on URI online judge for novice problem solver.
You can find details on this Link.
import java.text.DecimalFormat;
import java.util.Scanner;
/**
* @Author : Muhammad Harun-Or-Roshid
* @Date : Oct 9, 2016
* @Time : 5:42:42 PM
*/
public class Uri1021 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double n = sc.nextDouble();
if (n >= 0 && n <= 1000000.00) {
int notes[] = {100, 50, 20, 10, 5, 2};
double coins[] = {1.00, 0.50, 0.25, 0.10, 0.05, 0.01};
System.out.println("NOTAS:");
for (int i = 0; i < notes.length; i++) {
int t = (int) (n / notes[i]);
System.out.printf("%d nota(s) de R$ %.2f\n",t , (double)notes[i]);
n = toDouble(n - notes[i]*t);
}
System.out.println("MOEDAS:");
for (int i = 0; i < coins.length; i++) {
int t = (int) (n / coins[i]);
System.out.printf("%d moeda(s) de R$ %.2f\n", (int) (n / coins[i]), coins[i]);
n = toDouble(n - coins[i]*t);
}
}
}
private static double toDouble(double x){
DecimalFormat format = new DecimalFormat("#0.00");
return Double.valueOf(format.format(x));
}
}
by Muhammad Harun-Or-Roshid | Jan 29, 2019 | Problem Solving, URI
URI Problem (Age in Days) 1020:
Age in Days 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 8, 2016
* @Time : 10:45:35 PM
*/
public class Uri1020 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int years = n/365;
int months = n%365;
int days = months%30;
months = months/30;
System.out.println(years+" ano(s)\n"+months+" mes(es)\n"+days+" dia(s)");
}
}
by Muhammad Harun-Or-Roshid | Jan 29, 2019 | Problem Solving, URI
URI Problem (Time Conversion) 1019:
Time Conversion 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 8, 2016
* @Time : 10:23:50 PM
*/
public class Uri1019 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = 60;
int minute = n / x;
int second = n % x;
int hour = minute / x;
minute = minute % x;
System.out.println(hour + ":" + minute + ":" + second);
}
}
by Muhammad Harun-Or-Roshid | Jan 29, 2019 | Problem Solving, URI
URI Problem (Banknotes) 1018:
Banknotes 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 8, 2016
* @Time : 8:28:02 PM
*/
public class Uri1018 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if(n > 0 && n < 1000000){
int values[] = {100,50,20,10,5,2,1};
System.out.println(n);
for (int i = 0; i < values.length; i++) {
System.out.println(n/ values[i]+" nota(s) de R$ "+values[i]+",00");
n = n % values[i];
}
}
}
}
by Muhammad Harun-Or-Roshid | Jan 29, 2019 | Problem Solving, URI
URI Problem (Fuel Spent) 1017:
Fuel Spentis 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 8, 2016
* @Time : 8:06:03 PM
*/
public class Uri1017 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int s_time,distance;
s_time = sc.nextInt();
distance = sc.nextInt();
double cost = (double)(distance/12.0)*s_time;
System.out.printf("%.3f\n",cost);
}
}
by Muhammad Harun-Or-Roshid | Jan 29, 2019 | Problem Solving, URI
URI Problem (Distance) 1016:
Distance 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 8, 2016
* @Time : 7:58:58 PM
*/
public class Uri1016 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
System.out.println(2*x+" minutos");
}
}
by Muhammad Harun-Or-Roshid | Jan 28, 2019 | Problem Solving, UVa
UVa Problem (Train Swapping) 299:
Train Swapping is a basic problem on UVa online judge for novice problem solver.
You can find details on this Link.
import java.util.Scanner;
/**
* @Author : Muhammad Harun-Or-Roshid
* @Date : Oct 6, 2016
* @Time : 9:24:33 PM
*/
public class UVa299 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
for (int i = 0; i < testCase; i++) {
int inputLines = sc.nextInt();
if (inputLines >= 0 && inputLines <= 50) {
int inputArrays[] = new int[inputLines];
for (int j = 0; j < inputLines; j++) {
inputArrays[j] = sc.nextInt();
}
int swipTimes = 0;
for (int l = 0; l < inputArrays.length; l++) {
for (int k = 0; k < inputArrays.length - 1; k++) {
int a = inputArrays[k];
int b = inputArrays[k + 1];
if (a > b) {
inputArrays[k] = b;
inputArrays[k + 1] = a;
swipTimes++;
}
}
}
System.out.printf("Optimal train swapping takes %d swaps.\n", swipTimes);
}
}
}
}
by Muhammad Harun-Or-Roshid | Jan 28, 2019 | Problem Solving, URI
URI Problem (Distance Between Two Points) 1015:
Distance Between Two Points 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 6, 2016
* @Time : 9:24:33 PM
*/
public class Uri1015 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x1,y1,x2,y2;
x1 = sc.nextDouble();
y1 = sc.nextDouble();
x2 = sc.nextDouble();
y2 = sc.nextDouble();
double distence = Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2));
System.out.printf("%.4f\n",distence);
}
}
by Muhammad Harun-Or-Roshid | Jan 28, 2019 | Problem Solving, URI
URI Problem (Consumption) 1014:
Consumption 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 6, 2016
* @Time : 9:16:40 PM
*/
public class Uri1014 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int X = sc.nextInt();
double Y = sc.nextDouble();
double Z = X/Y;
System.out.printf("%.3f km/l\n",Z);
}
}
by Muhammad Harun-Or-Roshid | Jan 28, 2019 | Problem Solving, URI
URI Problem (The Greatest) 1013:
The Greatest 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 6, 2016
* @Time : 8:55:55 PM
*/
public class Uri1013 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A, B, C;
A = sc.nextInt();
B = sc.nextInt();
C = sc.nextInt();
int d = maior(maior(A, B), C);
System.out.println(d + " eh o maior");
}
private static int maior(int A, int B) {
return (A + B + Math.abs(A - B)) / 2;
}
}
by Muhammad Harun-Or-Roshid | Jan 28, 2019 | Problem Solving, URI
URI Problem (Area) 1012:
Area 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 6, 2016
* @Time : 8:38:17 PM
*/
public class Uri1012 {
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();
//a) the area of the rectangled triangle that has base A and height C.
double area_triangle = 0.5f*A*C;
//b) the area of the radius's circle C. (pi = 3.14159)
double area_radius = 3.14159*C*C;
//c) the area of the trapezium which has A and B by base, and C by height.
double area_trapezium = ((A+B)/2)*C;
//d) the area of the square that has side B.
double area_square = B*B;
//e) the area of the rectangle that has sides A and B.
double area_rectangle = A*B;
System.out.printf("TRIANGULO: %.3f\n",area_triangle);
System.out.printf("CIRCULO: %.3f\n",area_radius);
System.out.printf("TRAPEZIO: %.3f\n",area_trapezium);
System.out.printf("QUADRADO: %.3f\n",area_square);
System.out.printf("RETANGULO: %.3f\n",area_rectangle);
}
}