Conditional Statements
It was Christmas Eve and the celebrations remembering the birth of Jesus were going on in full swing at the Catheral Chapel. The Event Management Team had arranged for some exciting games after the mass worship and feast, where adults and kids of all ages participated very actively. "Chocolate Game" was organized for the kids which involved a standard chocolate of n by m pieces. More formally, chocolate is a rectangular plate consisting of n rows and m columns.
Two kids at a moment will play with the chocolate. First kid takes the chocolate and cuts it into two parts by making either a horizontal or vertical cut. Then, the second kid takes one of the available pieces and divides into two parts by either making a horizontal or vertical cut. Then the turn of first kid comes and he can pick any block of the available chocolates and do the same thing again. The player who cannot make a turn loses.
Write a program to find which of the kids will win if both of them play optimally. Output "Yes", if the kid who plays first will win, otherwise print "No".
Input Format:
The only line of the input contains two space separated integers n and m - the sizes of the chocolate.
Output Format:
Output a single line containing one word "Yes" (without quotes) if there is a sequence of moves leading to the winning of the person who moves first and "No" (without quotes) otherwise.
Refer sample input and output for formatting specifications.
Sample Input 1:
1 2
Sample Output 1:
Yes
Sample Input 2:
1 3
Sample Output 2:
No
Two kids at a moment will play with the chocolate. First kid takes the chocolate and cuts it into two parts by making either a horizontal or vertical cut. Then, the second kid takes one of the available pieces and divides into two parts by either making a horizontal or vertical cut. Then the turn of first kid comes and he can pick any block of the available chocolates and do the same thing again. The player who cannot make a turn loses.
Write a program to find which of the kids will win if both of them play optimally. Output "Yes", if the kid who plays first will win, otherwise print "No".
Input Format:
The only line of the input contains two space separated integers n and m - the sizes of the chocolate.
Output Format:
Output a single line containing one word "Yes" (without quotes) if there is a sequence of moves leading to the winning of the person who moves first and "No" (without quotes) otherwise.
Refer sample input and output for formatting specifications.
Sample Input 1:
1 2
Sample Output 1:
Yes
Sample Input 2:
1 3
Sample Output 2:
No
Solution:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int m,n,t;
m=sc.nextInt();
n=sc.nextInt();
t=m*n-1;
if(t%2!=0)
System.out.println("Yes");
else
System.out.println("No");
}
}
S2P1-WELCOME
Welcome
A recently launched attraction at the "Events Square" entertainment fair is the "Carnival of Terror" which is an interactive fun zone featuring scary, horror and Halloween stories.
The Entry tickets for the show is to be printed with a Welcome message along with an additional message for Children stating they should be accompanied by an adult. Given the age of the person visiting the scary house, the ticket should carry the additional message only for Children whose age is less than 15 years. The show organizers wanted your help to accomplish this task. Write a program that will get age as the input and display the appropriate message on the tickets.
Input Format:
First line of the input is an integer that corresponds to the age of the person.
Output Format:
Output should display the additional message "Please note that you should be accompanied by an adult" for Children less than 15 years. Otherwise it should print only the Welcome message.
Refer sample input and output for formatting specifications.
Sample Input 1:
20
Sample Output 1:
Welcome to the show
Sample Input 2:
14
Sample Output 2:
Welcome to the show
Please note that you should be accompanied by an adult
The Entry tickets for the show is to be printed with a Welcome message along with an additional message for Children stating they should be accompanied by an adult. Given the age of the person visiting the scary house, the ticket should carry the additional message only for Children whose age is less than 15 years. The show organizers wanted your help to accomplish this task. Write a program that will get age as the input and display the appropriate message on the tickets.
Input Format:
First line of the input is an integer that corresponds to the age of the person.
Output Format:
Output should display the additional message "Please note that you should be accompanied by an adult" for Children less than 15 years. Otherwise it should print only the Welcome message.
Refer sample input and output for formatting specifications.
Sample Input 1:
20
Sample Output 1:
Welcome to the show
Sample Input 2:
14
Sample Output 2:
Welcome to the show
Please note that you should be accompanied by an adult
Solution:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
if(a>=15)
System.out.println("Welcome to the show");
else
{
System.out.println("Welcome to the show");
System.out.println("Please note that you should be accompanied by an adult");
}
}
}
S2P3-THRILL RIDE
Thrill ride
"Fantasy Kingdom" is a brand new Amusement park that is going to be inaugurated shortly in the City and is promoted as the place for breath-taking charm. The theme park has more than 30 exhilarating and thrilling rides and as a special feature of the park, the park Authorities have placed many Booking Kiosks at the entrance which would facilitate the public to purchase their entrance tickets and ride tickets.
There are few rides in the park which are not suitable for Children and aged people, hence the park Authorities wanted to program the kiosks to issue the tickets based on people’s age. If the age given is less than 15 (Children) or greater than 60 (Aged), then the system should display as "Not Allowed", otherwise it should display as "Allowed". Write a block of code to help the Authorities program this functionality.
Input Format:
First line of the input is an integer that corresponds to the age of the person opting for the ride.
Output Format:
Output should display "Allowed" or "Not Allowed" based on the conditions given.
Refer sample input and output for formatting specifications.
Sample Input 1:
20
Sample Output 1:
Allowed
Sample Input 2:
12
Sample Output 2:
Not Allowed
There are few rides in the park which are not suitable for Children and aged people, hence the park Authorities wanted to program the kiosks to issue the tickets based on people’s age. If the age given is less than 15 (Children) or greater than 60 (Aged), then the system should display as "Not Allowed", otherwise it should display as "Allowed". Write a block of code to help the Authorities program this functionality.
Input Format:
First line of the input is an integer that corresponds to the age of the person opting for the ride.
Output Format:
Output should display "Allowed" or "Not Allowed" based on the conditions given.
Refer sample input and output for formatting specifications.
Sample Input 1:
20
Sample Output 1:
Allowed
Sample Input 2:
12
Sample Output 2:
Not Allowed
Solution:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
if(a>=15 && a<=60)
System.out.println("Allowed");
else
System.out.println("Not Allowed");
}
}
S2P4-LUCKY WINNER
Lucky Winner
It was the inaugural ceremony of "Fantasy Kingdom" Amusement park and the park Management has announced some lucky prizes for the visitors on the first day. Based on this, the visitors whose ticket number has the last digit as 3 or 8, are declared as lucky winners and attracting prizes are awaiting to be presented for them.
Write a program to find if the last digit of the ticket number of visitors is 3 or 8.
Input Format:
First line of the input is an integer that corresponds to the ticket number.
Output Format:
Output should display as "Lucky Winner" if the last digit of the ticket number is 3 or 8. Otherwise print "Not a Lucky Winner".
Refer sample input and output for formatting specifications.
Sample Input 1:
43
Sample Output 1:
Lucky Winner
Sample Input 2:
41
Sample Output 2:
Not a Lucky Winner
Write a program to find if the last digit of the ticket number of visitors is 3 or 8.
Input Format:
First line of the input is an integer that corresponds to the ticket number.
Output Format:
Output should display as "Lucky Winner" if the last digit of the ticket number is 3 or 8. Otherwise print "Not a Lucky Winner".
Refer sample input and output for formatting specifications.
Sample Input 1:
43
Sample Output 1:
Lucky Winner
Sample Input 2:
41
Sample Output 2:
Not a Lucky Winner
Solution:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int lastDigit=num%10;
if(lastDigit==3 || lastDigit==8)
System.out.println("Lucky Winner");
else
System.out.println("Not a Lucky Winner");
}
}
S2P8-TOTAL EXPENSES
Total Expenses
The much awaited event at the entertainment industry every year is the "Screen Awards". This year the event is going to be organized on December 25 to honour the Artists for their professional excellence in Cinema. The Organizers has this time decided to launch an online portal to facilitate easy booking of the Award show’s tickets.
They specifically wanted to provide an option for bulk booking in the portal, wherein there are many discounts announced. Write a program to help the Organizers to create the portal as per the requirement given below.
Given the ticket cost as 'X'.
If the number of tickets purchased is less than 50, there is no discount.
If the number of tickets purchased is between 50 and 100 (both inclusive), then 10% discount is offered.
If the number of tickets purchased is between 101 and 200(both inclusive), 20% discount is offered.
If the number of tickets purchased is between 201 and 400(both inclusive), 30% discount is offered.
If the number of tickets purchased is between 401 and 500(both inclusive), 40% discount is offered.
If the number of tickets purchased is greater than 500, then 50% discount is offered.
Input Format:
First line of the input is an integer that corresponds to the cost of the ticket ‘X’.
Second line of the input is an integer that corresponds to the number of tickets purchased.
Output Format:
Output should display a double value, which gives the total expenses in purchasing the tickets after discounts. Display the output correct to 2 decimal places.
Refer sample input and output for formatting specifications.
Sample Input 1:
100
5
Sample Output 1:
500.00
Sample Input 2:
100
300
Sample Output 2:
21000.00
They specifically wanted to provide an option for bulk booking in the portal, wherein there are many discounts announced. Write a program to help the Organizers to create the portal as per the requirement given below.
Given the ticket cost as 'X'.
If the number of tickets purchased is less than 50, there is no discount.
If the number of tickets purchased is between 50 and 100 (both inclusive), then 10% discount is offered.
If the number of tickets purchased is between 101 and 200(both inclusive), 20% discount is offered.
If the number of tickets purchased is between 201 and 400(both inclusive), 30% discount is offered.
If the number of tickets purchased is between 401 and 500(both inclusive), 40% discount is offered.
If the number of tickets purchased is greater than 500, then 50% discount is offered.
Input Format:
First line of the input is an integer that corresponds to the cost of the ticket ‘X’.
Second line of the input is an integer that corresponds to the number of tickets purchased.
Output Format:
Output should display a double value, which gives the total expenses in purchasing the tickets after discounts. Display the output correct to 2 decimal places.
Refer sample input and output for formatting specifications.
Sample Input 1:
100
5
Sample Output 1:
500.00
Sample Input 2:
100
300
Sample Output 2:
21000.00
Solution:
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
double x,num,mul;
x=sc.nextDouble();
num=sc.nextDouble();
if(num<50)
{
mul=x*num;
System.out.printf("%.2f",mul);
}
else
if(num>=50 && num<=100)
{
mul=(x*num)*(1-0.1);
System.out.printf("%.2f",mul);
}
else
if(num>=101 && num<=200)
{
mul=(x*num)*(1-0.2);
System.out.printf("%.2f",mul);
}
else
if(num>=201 && num<=400)
{
mul=(x*num)*(1-0.3);
System.out.printf("%.2f",mul);
}
else
if(num>=401 && num<=500)
{
mul=(x*num)*(1-0.4);
System.out.printf("%.2f",mul);
}
else
if(num>500)
{
mul=(x*num)*(1-0.5);
System.out.printf("%.2f",mul);
}
}
}
Hanging Bridge
At the annual "KrackerJack Karnival", there was a newest attraction ever in the City, the "Hanging Bridge". Visitors will be able to walk 200ft on the bridge, hanging around 50ft above the ground, and enjoy a wide-angle view of the breathtaking greenery.
The Hanging Bridge was inaugurated successfully in co-ordination with the Event Manager Rahul. There is a limit on the maximum number of people on the bridge and Rahul has to now ensure the count of people on the bridge currently should not exceed the limit. He then approximately estimated that C adults and D kids who came to the show, were on the hanging bridge. He also noticed that there are L legs of the people touching the bridge.
Rahul knows that kids love to ride on the adults and they might ride on the adults, and their legs won't touch the ground and hence he would miss counting their legs. Also Rahul knew that the adults would be strong enough to ride at max two kids on their back.
Rahul is now wondering whether he counted the legs properly or not. Specifically, he is wondering is there some possibility of his counting being correct. Please help Rahul in finding it.
Input Format:
The only line of input contains three space separated integers C, D, L denoting number of the adults, number of the kids and number of legs of people counted by Rahul, respectively.
Output Format:
Output a single line containing a string "yes" or "no" (both without quotes) according to the situation.
Refer sample input and output for formatting specifications.
Sample Input 1:
1 1 4
Sample Output 1:
yes
Sample Input 2:
2 4 16
Sample Output 2:
no
The Hanging Bridge was inaugurated successfully in co-ordination with the Event Manager Rahul. There is a limit on the maximum number of people on the bridge and Rahul has to now ensure the count of people on the bridge currently should not exceed the limit. He then approximately estimated that C adults and D kids who came to the show, were on the hanging bridge. He also noticed that there are L legs of the people touching the bridge.
Rahul knows that kids love to ride on the adults and they might ride on the adults, and their legs won't touch the ground and hence he would miss counting their legs. Also Rahul knew that the adults would be strong enough to ride at max two kids on their back.
Rahul is now wondering whether he counted the legs properly or not. Specifically, he is wondering is there some possibility of his counting being correct. Please help Rahul in finding it.
Input Format:
The only line of input contains three space separated integers C, D, L denoting number of the adults, number of the kids and number of legs of people counted by Rahul, respectively.
Output Format:
Output a single line containing a string "yes" or "no" (both without quotes) according to the situation.
Refer sample input and output for formatting specifications.
Sample Input 1:
1 1 4
Sample Output 1:
yes
Sample Input 2:
2 4 16
Sample Output 2:
no
Solution: (c+d>=l/2 ->yes else no
more more questions
ReplyDelete