[go: up one dir, main page]

0% found this document useful (0 votes)
38 views69 pages

Wa0002.

Uploaded by

prathapdec13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views69 pages

Wa0002.

Uploaded by

prathapdec13
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

1)Problem Description:

On one beautiful Sunday Selvan went to Aaron's house for exam preparation.

They have decided to study Mathematics subject because they have exams by coming Monday,
Aaron is a master in Mathematics but Selvan is not so good in Mathematics so James trained
with Selvan for getting a high score in the exam.

After teaching some problems to Selvan.Aaron have given some tasks to Selvan to solve .

The problem is to convert input float into a double.

Can you help Selvan in finding the solution ?

Constraints:
1.00 ≤ num1 ≤ 100.00
1.00 ≤ num2 ≤ 100.00
1.00 ≤ resnum1 ≤ 100.00
1.00 ≤ resnum2 ≤ 100.00
Input Format:

The first and second line of the input represents two different input value of type float.
Output Format:

The first and second line of the output represents outputs of first and second line of input of type
double.

Code:-
import java.util.Scanner;
public class Class431242000031 {
public static void main(String[] args) {
// Create a Scanner object for reading input
Scanner input = new Scanner(System.in);
// Read the first float value from input
float num1 = input.nextFloat();
// Read the second float value from input
float num2 = input.nextFloat();
// Convert float to double (implicit conversion)
double resnum1 = num1;
double resnum2 = num2;
// Print the results as double values using println method
// Print with six decimal places
System.out.println(String.format("%.6f", resnum1));
System.out.println(String.format("%.6f", resnum2));
// Close the scanner
input.close();
}
}

Problem Description:

Nancy bought apples in a fruit shop.


The shop keeper specified the the bill amount. Nancy also given some amount to the
shop keeper for paying the bill.But she likes to know the quotient and remainder after
dividing the amount given by her by the bill amount specified by shop keeper.
Can you help nancy in finding it?

Constraint : 5 ≤ amtgiven≤ 2500

5 ≤ billamt ≤ 2500

Input Format:
First Line: Integer value of amtgiven representing the amount given by nancy.

Second Line: Integer value of billamt representing the amount specified by the shop
keeper

Output Format

First Line: Print the Quotient in integer format.

Second Line: Print the Remainder in integer format.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
// Create a Scanner object for reading input
Scanner input = new Scanner(System.in);
// Read the amount given by Nancy
int amtgiven = input.nextInt();
// Read the bill amount specified by the shop keeper
int billamt = input.nextInt();
// Calculate the quotient and remainder
int quotient = amtgiven / billamt;
int remainder = amtgiven % billamt;
// Print the results with labels
System.out.println("Quotient:" + quotient);
System.out.println("Remainder:" + remainder);
// Close the scanner
input.close();
}
}
Problem Description:

Tina's brother gave her a friendly task of calculating the number of squares in a board
that has n*n squares of dimensions 1cm *1cm each.
Help her to find the number of total squares including all small and big ones.

Constraints:
2 ≤ n ≤ 20
Input Format: The only line of the input represents a value of "n"
Output Format:

Print the number of squares in the n*n board."

Code :-

import java.util.Scanner; // 1
public class Class431242000031{ // 2
public static void main(String[] args) { // 3
Scanner input = new Scanner(System.in); // 4
int n = input.nextInt(); // 5

int x = (n * (n + 1) * (2 * n + 1)) / 6; // 6

System.out.println(x); // 7
} // 8
} // 9

Problem Description:
Binita is playing a chess. The game will be played on a rectangular grid consisting of N rows
and M columns. Initially all the cells of the grid are uncolored.Binita's initial score is zero. At
each turn, he chooses some cell that is yet not colored, and colors that cell.

The score obtained in this step will be number of neighboring colored cells of the cell that Binita
colored in this step. Two cells are neighbors of each other if they share a side between them.
The game will end when all the cells are colored. Finally, total score obtained at the end of the
game will sum of score obtained in each turn. Binita wants to know what maximum score he can
get? Can you please help her in finding this out?

Constraints:
1 ≤ N, M ≤ 50

Input Format:
The Only line of input contains two space-separated integers N, M denoting the dimensions of
the grid.

Output Format:
Print the output a single line containing an integer corresponding to the maximal possible score
Binita can obtain.

Code:-
import java.util.Scanner;
public class Class431242000031 {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner input = new Scanner(System.in);
// Read the number of rows and columns from input
int n = input.nextInt(); // Number of rows
int m = input.nextInt(); // Number of columns
// Calculate the maximum score using a simplified formula
// Total score = 2 * (n * m - 1) - (n + m - 2)
int ans = 2 * (n * m - 1) - (n + m - 2);
// Print the result
System.out.println(ans);
// Close the Scanner object to release resources
input.close();
}
}

During the IPL Match between CSK and MI, as a part of IPL contest the question was asked to
the fans.Who are all giving the correct answer to that question will get the free VIP box ticket for
the Final for which CSK have already qualified .The question is convert given integer number to
octal and hexadecimal number respectively. Abilash is an die heart CSK fan. Can you help him
answer the question so that he can watch CSK play the final from VIP box?

Constraints:

1≤iplno≤10000

Input Format:

Only line of input has single integer number that need to be converted.

Output Format:
In the First line of output print the octal number equivalent to the input value.In the Second line
of output print the hexadecimal number equivalent to the input value.

Code:-

import java.util.Scanner;
public class Class431242000031 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // Read input
int iplno = input.nextInt(); // Read integer
System.out.println(Integer.toOctalString(iplno)); // Octal output
System.out.println(Integer.toHexString(iplno)); // Hexadecimal output
input.close(); // Close scanner
}
}

Problem Description:

Phoenix mall in the capital city of Washington and it is rectangular in shape when it is seen on
the map with the size n x m meters. On the occasion of the jubilee anniversary, a decision was
taken to pave the Square with square marbles stones. Each stone is of the size n × n.
Can you what is the least number of stones needed to pave the Square? It's allowed to cover
the surface larger than the Mall Square, but the Square has to be covered. It's not allowed to
break the stones. The sides of stones should be side by side(parallel) to the sides of the
Square.

Constraints:

1 ≤ n ≤ 10^9

1 ≤ m ≤ 10^9
1 ≤ a ≤ 10^9

Input Format:

The only line of input contains three positive integer numbers n, m and a separated by a space
.Output Format:
Print the needed number of stones.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
int a = input.nextInt();
input.close();
// Compute and print the number of stones
System.out.println(((n + a - 1) / a) * ((m + a - 1) / a));
}
}

Problem Description:

Tina's trainer have given her two positive integers U and V. Now her task is ti find the number of
pairs of positive integers (X,Y) such that 1≤X≤U, 1≤Y≤V and X+Y is even.Tina is finding difficult
to understand the problem.Can you help her solving the problem?

Constraints
1≤A,B≤75
Input Format:
The only line of each test case contains two space-separated integers U and V.

Output Format:
In the only line of output print a single line containing one integer that represents the the number
of valid pairs.

Program:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int U = input.nextInt(); // Read integer U
int V = input.nextInt(); // Read integer V
input.close();
// Calculate and print the number of valid pairs
System.out.println((U / 2) * (V / 2) + ((U + 1) / 2) * ((V + 1) / 2));
}
}

Problem Description:

Elavenil runs a popular bakery in her native. Elavenil has now finished baking and frosting her
cupcakes, it's time to package them. Elavenil has N cupcakes, and needs to decide how many
cupcakes to place in each package. Each package must contain the same number of cupcakes.
Elavenil will choose an integer A between 1 and N, inclusive, and place exactly A cupcakes into
each package. Elavenil makes as many packages as possible. Elavenil then gets to eat the
remaining cupcakes. Elavenil enjoys eating cupcakes very much. Help Elavenil choose the
package size A that will let him eat as many cupcakes as possible.

Constraints:

2 ≤ N ≤ 10000

Input Format:

Only line of input consists of a single integer N representing the number of cupcakes.

Output Format:

Print the package size that will maximize the number of leftover cupcakes. If multiple package
sizes will result in the same number of leftover cupcakes, print the largest such size.

Program:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt(); // Read the number of cupcakes
System.out.println((n / 2) + 1); // Compute and print the optimal
package size
input.close();
}
}
Problem Description:
Arif came from a very low income family. However, his father Irfan, sent him abroad for the
purpose of studying. Arif also concentrated well in his learning keeping in mind his father’s
poverty. Arif was excellent in mathematics. One day Arif had a computer class and his
computer teacher asked him to create a programming logic for the mathematics problem of
multiplying two numbers of type float.
Constraints:
1.00≤ var1 ≤1000.00
1.00≤ var2≤1000.00

Input Format:
The only line of input has two floating point numbers separated by space

Output Format:
In the only line of output print the result of the multiplication with 4 values after decimal point.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float val1 = input.nextFloat(); // Read the first floating-point number
float val2 = input.nextFloat(); // Read the second floating-point
number
input.close();

// Multiply the two values


float result = val1 * val2;

// Print the result formatted to 4 decimal places


System.out.println(String.format("%.4f", result));
}
}
Problem Description:
Binita was travelling from Chennai to Delhi in Rajdhani Express. The train have arrived at the
destination later than the estimated time. So, Binita wants to know the total number of hours and
minutes the train was delayed.Can you help Binita in finding the exact hour and time Rajdhani
Express was delay on the day of Binita's journey?

Constraint:
100 ≤ tot_mins ≤ 550

Input Format:

The only line of input has single value of variable tot_mins of type integer representing total
minutes.

Output Format:

Print the Number of Hours and Minutes in a single line.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int tot_mins = input.nextInt(); // Read the total minutes
input.close();

// Calculate hours and minutes


int hours = tot_mins / 60;
int minutes = tot_mins % 60;

// Print the result


System.out.println(hours + " Hours and " + minutes + " Minutes");
}
}

Question description
Several ages ago Stratfordshire was a kingdom. The King of Stratfordshire adored math. That's
why, when he first visited one of his many palaces, he first of all paid attention to the floor in one
hall. The floor was tiled with hexagonal tiles.

The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall
and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.

To better visualize the situation, look at the picture showing a similar hexagon for a = 2, b = 3
and c = 4.

According to the legend, as the King of Stratfordshire obtained the values a, b and c, he almost
immediately calculated the total number of tiles on the hall floor. Can you do the same?

Constraints:

2 ≤ a, b, c ≤ 1000

Input Format:

The first line contains three integers: a, b and c.

Output Format:

Print a single number — the total number of tiles on the hall floor.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b,c; // Declare the variables
a=sc.nextInt(); // Read the first integer
b=sc.nextInt(); // Read the second integer
c=sc.nextInt(); // Read the third integer
sc.close();

// Calculate the total number of tiles using the corrected formula


int totalTiles = a * b + b * c + c * a - a - b - c + 1;

// Print the result


System.out.println(totalTiles);
}
}

Question description

Tony likes numbers n and k very much. Now Tony wants to find the smallest integer x greater
than n, so it is divisible by the number k.

Constraints:

1 ≤ n, k ≤ 109

Input Format:

The only line contains two integers n and k .

Output Format:

Print the smallest integer x > n, so it is divisible by the number k.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,k; // Test Case 1: Declare variables
n=sc.nextInt(); // Test Case 2: Read integer n
k = sc.nextInt(); // Read integer k
sc.close();

// Calculate the smallest integer x > n that is divisible by k


int x = (n + k) - (n % k);

// Print the result


System.out.println(x); // Output the result
}
}

Question description

During the La Liga Match between Real Madrid and Barcelona, as a part of La Liga contest the
question was asked to the fans.Who are all giving the correct answer to that question will get
the free VIP box ticket for the Final for which Atletico Madrid have already qualified .The
question is to take two numbers N and M as input and print the boolean value as “True” or
“False” whether N is greater than or lesser than M and vice versa.

Constraints

1≤N≤100

1≤M≤100

Input Format:

Single line input of two numbers N and M separated by a space

Output Format:
The corresponding boolean value as “True” or “False” after checking the condition
import java.util.*; // Import all classes from the java.util package
public class Class431242000031{
public static void main(String[] args) {
Scanner r = new Scanner(System.in); // Create Scanner object 'r'
int N, M; // Declare variables
N = r.nextInt(); // Read integer N
M = r.nextInt(); // Read integer M
r.close();

// Check if N is greater than or equal to M and if N is less than or


equal to M
boolean isGreaterOrEqual = N >= M; // True if N is greater than or
equal to M
boolean isLesserOrEqual = N <= M; // True if N is less than or equal
to M

// Print the results


System.out.println(isGreaterOrEqual); // Output the result for N >= M
System.out.println(isLesserOrEqual); // Output the result for N <= M
}
}

Question description

Some country is populated by wizards. They want to organize a demonstration.There are n people living
in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x
people) do not support the wizards and aren't going to go to the demonstration. We know that the city
administration will react only to the demonstration involving at least y percent of the city people. Having
considered the matter, the wizards decided to create clone puppets which can substitute the city people
on the demonstration.

So all in all, the demonstration will involve only the wizards and their puppets. The city administration
cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the
administration will consider the city to be consisting of only n people and not containing any clone
puppets.

Help the wizards and find the minimum number of clones to create to that the demonstration had no less
than y percent of the city people.

Constraints:

1 ≤ n, x, y ≤ 104,

x≤n

Input Format:

The first line contains three space-separated integers, n, x, y - the number of citizens in the city, the
number of wizards and the percentage the administration needs, correspondingly.

Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration
more people that actually live in the city ( > n).

Output Format:

Print a single integer — the answer to the problem, the minimum number of clones to create, so that the
demonstration involved no less than y percent of n (the real total city population).

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n,x,y;
n = sc.nextInt();
x = sc.nextInt();
y=sc.nextInt();
sc.close();

int req = (int) Math.ceil(y * (double) n / 100);


System.out.println(Math.max(0, req - x));
}
}

Question description:

Franklin has unlimited number of coins with values 1,2,…,n. He wants to select some set of
coins having the total value of S.It is allowed to have multiple coins with the same value in the
set. What is the minimum number of coins required to get sum S? Can you calculate that for him
quickly?

Constraints:

1≤n≤100000

1≤S≤10^9

Input Format:

The only line of the input contains two integers n and S

Output Format:

Print exactly one integer - the minimum number of coins required to obtain sum S.

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int S = sc.nextInt();
sc.close();

int coins = S / n + (S % n == 0 ? 0 : 1);


System.out.println(coins);
}
}

m Question description

Agent Hitman 47 is preparing to steal an antique diamond piece from a museum. As it is fully guarded and they are guarding it
using high technologies, it's not easy to steal the piece. There are three circular laser scanners in the museum which are the main
headache for Agent Hitman 47 . The scanners are centered in a certain position, and they keep rotating maintaining a certain
radius. And they are placed such that their coverage areas touch each other as shown in the picture below:

Here R1, R2 and R3 are the radii of the coverage areas of the three laser scanners. The diamond is placed in the
place blue shaded region as in the picture. Now your task is to find the area of this region for Agent Hitman 47 , as he
needs to know where he should land to steal the diamond.

Constraints:
0 < R1, R2, R3 ≤ 100

Input Format:

Each case starts with a line containing three real numbers denoting R1, R2 and R3 . And no number contains more
than two digits after the decimal point.

Output Format:

Print the case number and the area of the place where the diamond piece is located rounded off to 4 decimal points

Code:-

import java.util.*;
import java.lang.Math;
public class Class431242000031{
public static void main(String[] args) {
double r1,r2,r3;
double s, ae, a, b, c, e, x, y, z, s1;
Scanner input = new Scanner(System.in);
r1 = input.nextDouble();
r2 = input.nextDouble();
r3 = input.nextDouble();
a = r1 + r2;
b = r2 + r3;
c = r3 + r1;
x = Math.acos((b * b + c * c - a * a) / (2 * b * c));
y = Math.acos((a * a + c * c - b * b) / (2 * c * a));
z = Math.acos((a * a + b * b - c * c) / (2 * a * b));
s = (a + b + c) / 2;
s1 = 0.5 * ((y * r1 * r1) + (z * r2 * r2) + (x * r3 * r3));
ae = Math.sqrt(s*(s-a)*(s-b)*(s-c));
e = ae - s1;
String t = String.format("%.4f", e);

Question description

Felix starts with an integer n.In one move, he can perform one of the following operations:
● divide n by one of its proper divisors, or
● subtract 1 from n if n is greater than 1.

A proper divisor is a divisor of a number, excluding itself. For example, 1, 2, 4, 5, and 10 are
proper divisors of 20, but 20 itself is not.What is the minimum number of moves Felix is required
to make to reduce n to 1?

Constraints:

1≤n≤10^9

Input Format:

The only line of each test case contains a single integer n .

Output Format:

For each test case, output the minimum number of moves required to reduce n to 1.

Code:-

import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
// Determine if n is odd (n & 1 will be 1 if n is odd, 0 if n is even)
int m = Math.min(n&1, 0);
// Determine the result based on whether n is even or odd
int s = (n % 2 == 0) ? 2 : 3;
// Output the result
System.out.println(s);
}
}
​ Question description

You are given AB, AC and BC. DE is parallel to BC. You are also given the area ratio
between ADE and BDEC. You have to find the value of AD.

Constraints:

1≤ AB, AC, BC≤ 100

Input Format:

Each case begins with four real numbers denoting AB, AC, BC and the ratio of ADE and BDEC
(ADE / BDEC). You can safely assume that the given triangle is a valid triangle with positive
area.

Output Format:

For each case of input you have to print AD rounded off to 4 decimal places

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Declare all variables with double type
double AB,AC,BC,AD,ADE,ABC,rat;

// Read inputs
AB = sc.nextDouble();
AC = sc.nextDouble();
BC = sc.nextDouble();
rat=sc.nextDouble(); // Read the ratio of areas

// Compute AD using the given area ratio


// The correct formula given the context should be computed based on
geometric relationships
AD = AB * Math.sqrt(rat / (1 + rat));

// Output AD rounded to 4 decimal places


System.out.printf("%.4f%n", AD);

sc.close();
}
}

Question description

You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its
three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of
this parallelepiped.

Constraints:

1≤A, B, C≤10000

Input Format:

The first and the single line contains three space-separated integers A,B and C— the areas of
the parallelepiped's faces

Output Format:
Print a single number — the sum of all edges of the parallelepiped.

CODE:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
int x,y,z;
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z=sc.nextInt();
double a=Math.sqrt(x * y / z) + Math.sqrt(z * x / y) + Math.sqrt(z * y
/ x);
System.out.println(4 * (int) a);
}
}

Question description

Once upon a time, there lived a mad programmer. He loved to solve creative problems other
than anything. His wife loved him quite a lot but disliked his curiosity for the problems. One day
he came from office, his wife gave him a glass of cold lime juice. She was in a romantic mood
and waiting for some romantic stuff. But the programmer asked her curiously, "If I give u radius
of the top and bottom part of the glass and the height, can you come up with the volume of the
glass?" His wife became a bit disappointed but as she is smart she replied with a smile, "You
already have drunk some juice, and the glass is not full. If I give you the height of the juice, can
you find the volume of the remaining juice in the glass?" Then the programmer kissed his wife
and said, "You are the best problem setter in the world!"

Now he set the same problem for you. The radius of the upper part r1 and lower part r2 is given.
If height of the glass is h and height of the juice is p what is the volume of the juice in the glass?

Constraints:

1 ≤ r2 < r1 ≤ 100

1 ≤ p ≤ h ≤ 100

Input Format:

Each case starts with a line containing four integers r1 ,r2 ,h and p

Output Format:

For each case, print the case number and the volume of the juice in the glass, and the decimal
value should be rounded off to 4 decimal places

Code:-

import java.io.*;
import java.util.*;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double r1,r2,h,p,r,k,juice;
r1 = sc.nextDouble();
r2 = sc.nextDouble();
h = sc.nextDouble();
p=sc.nextDouble();
r = p / (h * 1.0) * (r1 - r2) + r2;
juice = (Math.PI / 3.0) * p * (r * r + r2 * r2 + (r * r2));
System.out.printf("%.4f%n",juice);
}
}

Question description

Charles has three socks in his drawer. Each sock has one of 10 possible colors, which are
represented by integers between 1 and 10. Specifically, the colors of the socks are A,B and C

Charles has to wear two socks which have the same color. Help Charles find out if that is
possible or not. Charles has three socks in his drawer. Each sock has one of 10 possible colors,
which are represented by integers between 1 and 10. Specifically, the colors of the socks are
A,B and C

Charles has to wear two socks which have the same color. Help Charles find out if that is
possible or not.

Explanation:

Since there are no two socks with the same color, Charles cannot wear a pair of socks with the
same color.

Constraints

1≤A,B,C≤10
Input Format:

The first and only line of the input contains three space-separated integers A,B and C

Output Format:

Print a single line containing the string “YES” if it is possible for Charles to wear two socks with
the same color or “NO” if it is impossible.

Code:-

import java.io.*;
import java.util.*;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a, b, c;
a = input.nextInt();
b = input.nextInt();
c = input.nextInt();
if (a == b || b == c || c == a) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}

Question description:

Parker is a Stock Trader and works at the New York stock exchange.

While purchasing the stock at check out trading system assigns two values total stock value and
displayed stock value
Displayed stock value is equal to total stock value if number of stocks are 10 or more.

Otherwise displayed stock value will be [TOTAL STOCK VALUE+ 100 x (10 - NO. OF STOCKS)]

Parker has purchased N number of stocks and total stock value is M.

Constraints:

1≤N≤100

1≤M≤4000

Input Format:

Only line of input has two values N M of type integer separated by a space.

Output Format:

Print the Displayed Stock Value

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N,M;
N = sc.nextInt();
M = sc.nextInt();

int displayedStockValue;
if (N <= 9) { // Use <= to check if N is less than or equal to 9
displayedStockValue = M + 100 * (10 - N);
} else {
displayedStockValue = M;
}

System.out.println(displayedStockValue);

sc.close();
}
}

Question description

John has a little brother and his name is Mathew.

Mathew is really young and is just starting to learn english, John wants to explain him about
consonants and vowels

Help john to write a program that takes a letter as input and displays whether the entered
character is a consonant or vowel

Constraints

1≤N≤10^5

|S|=N

Input Format:

Single line input has a character input of single letter

Output Format:

Print whether it is a “Vowel” or “Consonant”

Question description
John has a little brother and his name is Mathew.

Mathew is really young and is just starting to learn english, John wants to explain him about
consonants and vowels

Help john to write a program that takes a letter as input and displays whether the entered
character is a consonant or vowel

Constraints

1≤N≤10^5

|S|=N

Input Format:

Single line input has a character input of single letter

Output Format:

Print whether it is a “Vowel” or “Consonant”

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Read the input character


char ch = sc.next().toLowerCase().charAt(0); // Use charAt(0) to get
the first character

// Check if the character is a vowel


if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
// Use || for logical OR
System.out.println("Vowel");
} else { // Use else to handle consonants
System.out.println("Consonant");
}

sc.close(); // Close the scanner


}
}

Question description

Mr. Zach is the head of physical education in a school and the physical education department
has decided to analyze the height of all the students.

The state championship tournaments are coming up and they have to select a proper basketball
team and they want to collect the details of students.

Can you help them on this task?

Height is taken based on centimeter

If the height is ≤150 the person is short

If the height is ≥150 and ≤175 the person is average height

If the height is >175 and ≤240 the person is Tall

Constraints
1≤height≤10^4

Input Format:

Single line input has decimal value which specifies height in cm

Output Format:

Print whether the person is “Tall”, “Average Height” or “Short”

Code:-

import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Declare the height variable as float


float height;

// Read the height input


height = sc.nextFloat();

// Determine the height category


if (height <= 150) { // Check if height is <= 150
System.out.println("Short");
} else if (height <= 175) { // Check if height is between 151 and 175
System.out.println("Average Height");
} else if (height <= 240) { // Check if height is between 176 and 240
System.out.println("Tall");
}

sc.close(); // Close the scanner


}
}

Question description

Jones has got a task from his boss and he needs to finish it by evening
He gave him a set of phone numbers and he has to reverse the digits of those phone numbers
and generate new phone numbers which are going to be used by the company

Help Jones to complete the task quick since he wants to watch the football match this evening

Constraints

1≤n≤100

1≤k≤10

Input Format:

First line, contains n number of test cases

Followed by no. of phone numbers

Output Format:

Reversed digits of n phone numbers in separate lines

Code:-
import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n,remainder,reverse;

n = input.nextInt();

while (n-- > 0) {


int num = input.nextInt();
reverse = 0;

while (num > 0) {


remainder = num % 10;
reverse = reverse * 10 + remainder;
num /= 10;
}

System.out.println(reverse);
}

input.close();
}
}
Question description

Bill was solving some problems in his math textbook and after he was done his friend Ray gave
him a challenge

He gave him the sizes of angles of a simple quadrilateral (in degrees) A,B,C and D in some
order along its perimeter. Bill has to determine whether the quadrilateral is cyclic.

Note: A quadrilateral is cyclic if and only if the sum of opposite angles is 180 degrees

Constraints:

1≤T≤10^4

1≤A,B,C,D≤357

A+B+C+D=360

Input Format:

The first line of the input contains a single integer T denoting the number of test cases. The
description of T test cases follows.

The first and only line of each test case contains four space-separated integers A, B, C and D.

Output Format:

Print a single line containing the string "YES" if the given quadrilateral is cyclic or "NO" if it is
not (without quotes).
Code:-

import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int A,B,C,D;
int n = input.nextInt();

while (n != 0) {
A = input.nextInt();
B = input.nextInt();
C = input.nextInt();
D = input.nextInt();

if ((A + C) == (B + D)) {
System.out.println("YES");
} else {
System.out.println("NO");
}

n--;
}

input.close();
}
}

Question description

You are given the height H (in metres) and mass M (in kilograms) of Tony. The Body Category 4:
Obesity if BMI ≥ 30
Constraints:

1≤T≤Mass Index (BMI) of a person is computed as M/(H^2)

Report the category into which Tony falls, based on his BMI:

● Category 1: Underweight if BMI ≤18


● Category 2: Normal weight if BMI is {19, 20,..., 24}
● Category 3: Overweight if BMI is {25, 26,..., 29}

2*10^4

1≤M≤10^4

1≤H≤10^2

Its guaranteed that H^2 divides M

Input Format:

• The first line of input will contain an integer, T, which denotes the number of testcases. Then
the testcases follow.

• Each testcase contains a single line of input, with two space separated integers, M, H, which
denote the mass and height of Tony respectively.

Output Format:

For each testcase, output in a single line, 1, 2, 3 or 4, based on the category in which Tony falls.

Code:-
import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
float bmi,m,h;
int n = input.nextInt();

while (n-- > 0) {


m = input.nextFloat();
h = input.nextFloat();
bmi = m / (h * h);

if (bmi <= 18) System.out.println(1);


else if (bmi <= 24) System.out.println(2);
else if (bmi <= 29) System.out.println(3);
else System.out.println(4);
}

input.close();
}
}

Question description

Max has X coins worth 1 rupee each and Y coins worth 2 rupees each. He wants to distribute all
of these X+Y coins to his two sons so that the total value of coins received by each of them is
the same. Find out whether Max will be able to do so.

Constraints:

1≤T≤10^3

0≤X,Y≤10^8

X+Y>0
Input Format:

The first line of input contains a single integer T, denoting the number of testcases.The
description of T test cases follows. Each test case consists of a single line of input containing
two space- separated integers X and Y.

Output Format:
For each test case, print "YES" (without quotes) if Chef can distribute all the coins equally and
"NO" otherwise.

Code:-

import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();

while (n != 0) {
int x = input.nextInt();
int y = input.nextInt();
int amt = x + (y * 2);

if (amt % 2 == 0) {
System.out.println("YES");
} else {
System.out.println("NO");
}

n--;
}

input.close();
}
}

Question description

Steve and his friend went outside to watch a movie.On their way back home they thought to
play a game for fun,They need to count the number of digits of any number they come across
let it be a vehicle license, street no. ,addresses any random number as quickly as possible

Constraints

1≤k≤100 ,1≤m≤10000

Input Format:

First line integer input, n number of testcases Followed by the n lines of integer numbers

Output Format:

Number of digits of corresponding number in separate line

Code :-

import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long k,c;
int n = input.nextInt();while(n!=0)
{
c=0;
k=input.nextInt();
while(k>0)
{
k=k/10;
c++;
}
System.out.println(c);
n--;
}
}
}

Question description

Selvan is solving his mathematics homework.He came across a question where he needed to
calculate the sum of first n natural numbers and check whether the sum is odd or even .Can you
help him solve this problem since he is running out of time and he needs to submit his
homework tomorrow.

Formula:

Sum of n natural numbers= (n x (n+1))/2

Constraints

1≤n≤1000

Input Format:

Only one line of input has one integer n

Output Format:

First line, print sum of first n natural number

Second line, print whether “Even” or “Odd”

Code:-

import java.io.*;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int n,sum;
n = x.nextInt();
sum = (n * (n + 1)) / 2;
if (sum % 2 != 0)
System.out.println(String.format("%d\nOdd", sum));
else
System.out.println(String.format("%d\nEven", sum));
}
}
Question description

Intergalactic war has broken out and Daniel is a spy, he wants to send a message which is a set of
random numbers to his military base.Given an array of elements. Your task is to find the second
maximum element in the array. Because that is the number of spaceships the enemy is going to send to
destroy Daniel's galaxy.

Can you Help Daniel and save his galaxy?

Constraints

1 ≤ N ≤ 106

Input Format:

First line of input contains an integer N which specifies the number of elements in an array

Second line contains an integer array of n integers respectively

Output Format:

Print a single line output which contains the second largest element of an array

Code:-

import java.io.*;
import java.util.*;
public class Class431242000031{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new
InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
int[] a = Arrays.stream(reader.readLine().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
Arrays.sort(a);
System.out.println(a[N-2]);
}
}

Question description

Lucas and his friend were scratching the lottery cards and checking whether the numbers on
the screen would matchEventually Lucas and his friend got bored so his friend gave Lucas a
challenge. They considered the random numbers of lottery cards as an array of n positive
integers and an integer X and task is to find the frequency of X in the array.? Can you help
Lucas complete the task?

Constraints:

1≤N≤1000

1≤A[i]≤10^5

1≤X≤1000

Input Format:

The first line contains n, the number of integers

The second line containing N integers like A1,A2,A3,…….An

The third line contains the number X

Output Format:

The frequency or the number of times the number X has occurred in the array A1,A2,A2….An.

​ Code:-


import java.util.*;
public class Class431242000031{
public static void main(String[] args) {
int n,count=0;
int i;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int []arr=new int[n];
for (i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int v = sc.nextInt();
for (i = 0; i < n; i++) {
if (arr[i] == v) {
count++;
}
}
System.out.println(count);
}
}

Question description

Frederick opened his new store and he sells N number of items. Price of each item is
represented using an array P where Pi represents the price of item i. A customer always buys 3
items of the lowest price from his store.Find out the profit Frederick can make from that
customer. It is guaranteed that his store has at least 3 items.

Constraints:

3≤N≤10^5

1≤A[i]≤10^3

Input Format:
First line contains N which represents the number of items in Jon's store.

Second line contains N space separated integers P1,P2,P3,....,PN which represents the price of
each item.

Output Format:

Output in a single line answer the profit Frederick makes from those 3 items.

Code:-

import java.util.*;
public class Class431242000031{
public static void main(String[] args) {
Scanner S = new Scanner(System.in);
int n, i, sum = 0;
n = S.nextInt();
int s[] = new int[n];

for (i = 0; i < n; i++) {


s[i]= S.nextInt();
}

Arrays.sort(s);

for (i = 0; i < 3; i++) {


sum += s[i];
}

System.out.println(sum);
}
}

Question description
On Harold's birthday, Harold's friends have given him an array "a" consists of n distinct integers
.But the size of array "a" is too small. Harold wants a bigger array! Harold friends agreed to give
him a bigger array.

But only if Harold is able to answer what is the Largest element in an array

Constraints:

1 ≤k≤1000

1≤ a[i] ≤ 1000

0 ≤ n, i ≤ 10^6

Input Format:

The first line contains positive integer n

Next line contains n Space separated Integers(a[0],a[1],a[2],....a[n-1])

Output Format:

Output the Following-Largest Element

Code:-
import java.util.Arrays;
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of elements in the array
int n = scanner.nextInt();
// Initialize an array to store the elements
int[] array = new int[n];
// Read the elements into the array
for(int i=0;i<n;i++) {
array[i] = scanner.nextInt();
}
// Sort the array
Arrays.sort(array);
// The largest element is now the last element in the sorted array
System.out.println(array[n - 1]);
// Close the scanner
scanner.close();
}
}

Question description

Jacob has been bunking classes lately and has been caught by the guard flunking the class. His
class teacher gave him an extra homework as punishment. Jacob has to finish the work quickly
so

Given an array of size N consisting of only 0's and 1's. The array is sorted in such a manner that
all the 1's are placed first and then they are followed by all the 0's. Find the count of all the 0's.

Constraints:

1≤N≤105
0≤Arr[i]≤1
Input Format:
First line contains a single integer input which specifies the number of elements in an array

The second line of input contains n integers which are either 1 or 0

Output Format:

Print the number of zeros in the array.

Code:-

import java.util.Scanner;
import java.util.Arrays;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count = 0, n, i;
n = sc.nextInt();
int[] arr=new int[n];
for (i = 0; i < n; i++) {
arr[i] = sc.nextInt();
if (arr[i] == 0) {
count++;
}
}
System.out.println(count);
}
}

Question description

Ambrose has some distinct integer numbers a1,a2...an. Count number of pairs (i,j) such that:

● 1≤ i ≤ n
● 1≤ j ≤ n
● ai < aj

Constraints:
1 ≤ n ≤ 100000

0 ≤ ai ≤ 109

Input Format:

The first line of the input contains an integer T denoting the number of test cases. The
description of T test cases follows. The first line of each test case contains a single integer n
denoting the number of numbers Ambrose has. The second line contains n space-separated
distinct integers a1, a2, ..., an denoting these numbers.

Output Format:

For each test case, output a single line containing number of pairs for corresponding test case.

Code:-

import java.util.*;
public class Class431242000031{
public static void main(String[] args) {
Scanner x = new Scanner(System.in);
int n; // Line 5
n = x.nextInt();
long[] a =new long[n]; // Line 9
for (int i = 0; i < n; i++)
a[i]= x.nextInt(); // Line unchanged
Arrays.sort(a);
long c = 0;
for (int i = 0; i < n; i++) c += n - i - 1;
System.out.println(c);

}
}
Question description

Luke has just been introduced to the world of numbers! While experimenting with addition and
multiplication operations, the Luke came up with the following problem:

Given an array A of non-negative integers, how many pairs of indices i and j exist such that
A[i]*A[j] > A[i]+A[j] where i < j .

Now being a learner, Luke isn't able to solve this problem efficiently and hence turns to you for
help.

Constraints:
2 ≤ N ≤ 105

0 ≤ A[i] ≤106

Input Format:

The first line contains an integer N denoting the number of integers in the array. The next line
contains N space separated integers where the ith integer represents A[i].

Output Format:

Print the required number of pairs in a single line.

Code:-
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read the number of integers in the array
int n = scanner.nextInt();
int[] arr= new int[n];
// Read the integers into the array
for(int i=0;i<n;i++) {
arr[i] = scanner.nextInt();
}
// Count numbers greater than 1
int countGreaterThan1 = 0;
// Count pairs based on the conditions
for (int value : arr) {
if (value > 1) {
countGreaterThan1++;
}
}
// Calculate the number of valid pairs based on the count
long result = (countGreaterThan1 * (countGreaterThan1 - 1)) / 2;
// Print the result

Question description

Jennifer is a ballet dancer, she is trying a new set of moves for the upcoming show and she
wants a nice sequence of numbers to synchronize her moves with.

Her friend Isabelle told her about the pascals triangle.

Pascal's triangle is a never-ending equilateral triangle of numbers that follow a rule of adding
the two numbers above to get the number below. It also can be defined as a triangular array of
the binomial coefficients formed by summing up the elements of previous row.
Given a positive integer N, return the Nth row of pascal's triangle.

Can you help Isabelle write a code for her friend Jennifer?

Constraints:

1≤n≤1000

Input Format:

Only single line input which contains one integer which indicates the nth row of pascal's triangle

Output Format:

Print the corresponding nth row of the pascal's triangle

Code:-
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

int[] r = new int[n + 1];


r[0] = 1;
for (int k=1;k<=n;k++)
r[k] = (int)((long)r[k - 1] * (n - k + 1) / k);

for (int k=0;k<=n;k++)


System.out.print(r[k] + " ");
}
}

Question description:

Jared likes statistical analysis and likes dealing with big numbers a lot.So he came across the
census sheet of this years population and found a lot of huge numbers and wants to calculate
the sum of few.

Calculate and print the sum of the elements in an array, keeping in mind that some of those
integers may be quite large.

Can you help him out?

Constraints:
Input Format:

The first line of the input consists of an integer n.

The next line contains n space-separated integers contained in the array arr.

Output Format:

Print the integer sum of the elements in the array array.

Code:-
import java.util.Scanner;
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Read the number of elements


int n = sc.nextInt();

// Declare and initialize the array


long[] ab = new long[n];

// Read the elements into the array


for (int i = 0; i < n; i++) {
ab[i] = sc.nextLong();
}

// Close the scanner


sc.close();

// Compute the sum of the array elements


long sum = 0;
for (long num : ab) {
sum += num;
}

// Print the result


System.out.println(sum);
}


Question description

Tyson Fury was given a sequence A1,A2,…,AN. You may perform the following operation any
number of times: select any two adjacent elements Ai and Ai+1 and replace one of them with

(a real number, i.e. without rounding). You may also select each pair of
adjacent elements and each element to replace in multiple operations, i.e. any number of times.

Is it possible to make the sequence strictly increasing in a finite number of operations?

Constraints:

2≤N≤105

1≤Ai≤109 for each valid i

the sum of N over all test cases does not exceed 10^6

Input Format:

The first line of each test case contains a single integer N.

The second line contains N space-separated integers A1,A2,…,AN

Output Format:

Print a single line containing the string "Yes" if it is possible to make the sequence strictly
increasing or "No" otherwise (without quotes).

Code:-
import java.util.Scanner;

public class Class431242000031 {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Read the number of elements in the sequence
int N = sc.nextInt();

// Initialize an array to store the sequence


int[] sequence = new int[N];

// Read the sequence elements


for (int i = 0; i < N; i++) {
sequence[i] = sc.nextInt();
}

// Check if the number of inputs matches the given


count
if (sequence.length != N) {
System.out.println("Input count does not match
the number of elements specified.");
sc.close();
return;
}

// Check if the sequence is strictly increasing


boolean isStrictlyIncreasing = true;
for (int i = 0; i < N - 1; i++) {
if (sequence[i] >= sequence[i + 1]) {
isStrictlyIncreasing = false;
break;
}
}
// Output result
if (isStrictlyIncreasing) {
System.out.println("The sequence is strictly
increasing.");
} else {
System.out.println("The sequence is not strictly
increasing.");
}

sc.close();
}
}

Question description

Kendrick has been studying about geometrical shapes recently and he thought to write a rap
verse based on a geometrical shape and thought the name Pyramid sounds cool. So he wants
to write a couple of lines based on the volume of Trapezoid in his song but doesn't know how to
find the volume of a rectangular pyramid. Given the lengths of its length, width, and height are x,
y, and z, respectively. Can you help Kendrick find the volume of Trapezoid?

Constraints:

1≤x≤100

1≤y≤100

1≤z≤100

Input Format:

Single line input consists of a decimal floating point value representing the lengths of its length,
width, and height respectively separated by a space

Output Format:
Print the volume of the given rectangular pyramid rounded off to 4 decimal points.

Code:-

import java.util.Scanner;
class RectPyramidArea {
protected float x,y,z;
}
public class Class431242000031{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
RectPyramidArea area=new RectPyramidArea();
area.x= sc.nextFloat();
area.y= sc.nextFloat();
area.z = sc.nextFloat();

float volume = (area.x * area.y * area.z) / 3;


System.out.println(String.format("Volume of Rectangular Pyramid: %.4f",
volume));

sc.close(); // Always good practice to close the scanner


}
}

Question description

The cab fare in Leicester is as follows :

● For the first R kilometer, the fares is P


● For the subsequent distance it is Q per kilometer
Zane would most likely take the cab today for work since he gave his car for servicing. At last
he would know the total distance covered by cab.

Can you help him to calculate the total fare for the whole ride?

Constraints:

0≤R,P,Q,D≤105

Input Format:

Single line input contains four integers representing the first R kilometers followed by P which is
the corresponding fare for first R kilometers followed by Q which is the fare for the remaining
distance covered and D which is the total distance travelled and all of them are separated by a
space.

Output Format:

Print the value of total fare

Code:-

import java.util.Scanner;

public class Class431242000031 {

protected static class InitialFare {


int R, P; // Initial distance and fare

protected static class SubsequentFare {

int Q, D; // Fare per kilometer beyond initial and total distance

public static void main(String[] args) {

// Create a Scanner object to read input

Scanner sc = new Scanner(System.in);

// Initialize InitialFare and SubsequentFare objects

InitialFare IF = new InitialFare();

SubsequentFare SF = new SubsequentFare();

// Read values for InitialFare and SubsequentFare

IF.R = sc.nextInt();

IF.P = sc.nextInt();

SF.Q = sc.nextInt();

SF.D = sc.nextInt();

// Calculate the total fare


int totalFare;

if (SF.D <= IF.R) {

// If the total distance is less than or equal to the initial distance

totalFare = IF.P;

} else {

// Calculate the fare for the initial distance and subsequent distance

totalFare = IF.P + (SF.D - IF.R) * SF.Q;

// Print the total fare

System.out.println(totalFare);

}
Question description

Brody went across the neighbourhood to get some lemonade and he came across a lemonade
stand hosting a small contest and if the person who takes the challenge clears it up they get a
glass of lemonade for free. The statement of the contest was, given non negative integers u
and v (u≤v), and a positive integer w. Among the integers between u and v, inclusive, how
many are divisible by w?

Can you help Brody get a nice cool glass of lemonade for free?

Constraints:
1≤ u, v ≤1018

1≤ w ≤1018

Input Format:
Single line input contains three integers u, v and w separated by space

Output Format:

Print the number of the integers between u and v, inclusive, that are divisible by w.

import java.util.Scanner;
public class Class431242000031{
private static class InputNumbers {
protected int a,b,c;
public void find() {
int sum = 0;
for (int i = a; i <= b; i++) {
if (i % c == 0) {
sum += 1;
}
}
System.out.println(sum);
}
}
public static void main(String[] args) {
InputNumbers obj=new InputNumbers();
Scanner sc = new Scanner(System.in);
obj.a= sc.nextInt();
obj.b= sc.nextInt();
obj.c= sc.nextInt();
obj.find();
sc.close();
}

Question description

There are N vases placed in a row. Ethan is an artist and is painting


each of these vases in one of the K colors of his paint cans. For
aesthetic reasons, any two adjacent vases must be painted in
different colors.

Find the number of the possible ways to paint the vases.

Constraints:

1≤N≤1000

2≤K≤1000

Input Format:

Single line input consists on two integers N and K separated by a


space representing the number of vases N and the number of colors K
respectively

Output Format:

Print the number of the possible ways to paint the vases.


import java.util.Scanner;
public class Class431242000028{
// Class to encapsulate the number of vases and colors
private static class NumOfVases {
int N,K;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

// Create an instance of NumOfVases


NumOfVases vase=new NumOfVases();

// Read input values


vase.N= sc.nextInt();
vase.K= sc.nextInt();

// Calculate the number of possible ways to paint the vases


long result = vase.K; // Initial number of ways to paint the first vase
for (int i = 1; i < vase.N; i++) {
result *= (vase.K - 1); // Each subsequent vase has K-1 choices
}

// Output the result


System.out.println(result);
sc.close();
}
}

Question description

A lot of people in Casterbridge hate rain, but Lewis doesn’t. Over


the years Lewis developed a good tradition - when it rains, Lewis
goes onto the street and stays silent for a moment, and then he
contemplates the surrounding environment , enjoys the freshness, and
starts to think about big deeds he has to do.

Today everything had changed quiet a bit. Lewis went onto the street
with a cup containing water, which is his favorite drink. In a moment
when he was drinking water he noticed that the process became quite
long, the cup still contained water because of rain. Lewis decided to
make a formal model of what was happening and to find if it was
possible to drink all water in that situation.

Thus, his cup is a cylinder with diameter equals d centimeters.


Initial level of water in cup equals h centimeters from the bottom.

If he drank water at a speed equals v milliliters per second. But


rain goes with such speed that if he does not drink the water from
the cup, the level of water increases by e centimeters per second.
The process of drinking water from the cup and the addition of rain
to the cup goes on evenly and continuously.

Find the time needed to make the cup empty or find that it will never
happen. It is guaranteed that if it is possible to drink all water,
it will happen not later than after 104 seconds.

Note one milliliter equals to one cubic centimeter.

Constraints:

1 ≤ d, h, v, e ≤ 104
Input Format:

The only line of the input contains four integer numbers d, h, v, e


where:

● d — the diameter of your cylindrical cup,


● h — the initial level of water in the cup,
● v — the speed of drinking process from the cup in milliliters
per second,
● e — the growth of water because of rain if you do not drink from
the cup.

Output Format:

If it is impossible to make the cup empty, print "NO" (without


quotes).

Otherwise print "YES" (without quotes) in the first line. In the


second line print a real number - time in seconds needed the cup will
be empty which is rounded off to 4 decimals.

Code :-

import java.util.Scanner;

// Class RainCup to handle properties and calculations

class RainCup {

double diameter, initlevel, speed, growth; // Declared as doubles

// Method to calculate the time needed to empty the cup or determine


if it's not possible

public String calculateEmptyTime() {

double radius = diameter / 2.0;


double rainRate = Math.PI * radius * radius * growth;

double netRate = speed - rainRate;

if (netRate <= 0) return "NO";

double initialVolume = Math.PI * radius * radius * initlevel;

return String.format("YES\n%.4f", initialVolume / netRate);

// Class Class431242000028 to manage input and output

public class Class431242000031 {

public static void main(String[] args) {

Scanner S = new Scanner(System.in); // Use S as the scanner


variable

// Create an instance of RainCup

RainCup stats = new RainCup();

// Read inputs and directly assign to double fields

stats.diameter = S.nextDouble();

stats.initlevel = S.nextDouble();

stats.speed = S.nextDouble();

stats.growth = S.nextDouble();

// Calculate and output the result

System.out.println(stats.calculateEmptyTime());

// Close the scanner

S.close();

}
}

You might also like