Edwin, an enthusiastic kid visited the "Fun Fair Fest" along with his family. His father wanted him to purchase entry tickets from the counter for his family members. Being a little kid, he is just learning to understand about units of money. Edwin has paid some amount of money for the tickets, but he wants your help to give him back the change of Rs. N using minimum number of rupee notes.
Consider a currency system in which there are notes of seven denominations, namely, Rs. 1, Rs. 2, Rs. 5, Rs. 10, Rs. 50, Rs. 100. If the change given to Edwin Rs. N is input, write a program to compute smallest number of notes that will combine to give Rs. N.
Input Format:
First line of the input is an integer N, the change to be given to Edwin.
Output Format:
Output should display the the smallest number of notes that will combine to give N.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to the output.]
Sample Input and Output 1:
1200
12
Explanation:
currency denomination are:
12 x Rs. 100 notes
24 x Rs. 50 notes
120 x Rs. 10 notes
240 x Rs. 5 notes
600 x Rs. 2 notes
1200 x Rs. 1notes
12 is the minimum number of currency notes, so the output is 12.
Sample Input and Output 2:
242
7
Explanation:
currency denomination are:
Type1:
2 x Rs.100 notes
4 x Rs.10 notes
1 x Rs. 2 notes
There are 7 currency notes in this denomination
Type2:
4 x Rs. 50 notes
8 x Rs. 5 notes
2 x Rs. 1 notes
There are14 currency notes in this denomination
7 is the minimum number of currency notes, so the output is 7.
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int count=0,rem=1;
while(n!=0){
if(n%100==0){
count =n/100;
n =n%100;}
else{
count = count + n/100;
n = n%100;
if(n>=50){
if(n%50==0){
count = count + n/50;
n=n%50;}
else{
count = count + n/50;
n = n%50;
}
}
else if(n>=10){
if(n%10==0){
count = count + n/10;
n=n%10;}
else{
count= count+ n/10;
n = n%10;
}
}
else if(n>=5){
if(n%5==0){
count = count + n/5;
n=n%5;}
else{
count = count+ n/5;
n= n%5;
}
}
else if(n>=2){
if(n%2==0){
count = count + n/2;
n=n%2;}
else{
count = count + n/2;
n = n%2;
}
}
else if(n>=1){
if(n%1==0){
count = count + n/1;n=n%1;}
else{
count=count+1;
n = n%1;
}
}
}
}
System.out.println(count);
}
}
Question 2
Tim and Bob are off to a famous Education Fair " World Knowledge Forum " in New York. This time they have to travel without their guardians. Tim got very interested in the arrangement of seats inside the train coach.
The entire coach could be viewed as an arrangement of consecutive blocks of size 8.
Berth Number | Coach Number |
1-8 | 1 |
9-16 | 2 |
17-24 | 3 |
... and so on |
Each of these size-8 blocks is further arranged as:
1LB, 2MB, 3UB, 4LB, 5MB, 6UB, 7SL, 8SU |
9LB, 10MB, ... |
....... |
....... |
Here LB denotes lower berth, MB middle berth, and UB upper berth.
The following berths are called Co-Partners in Train:
3 UB | 6 UB |
2 MB | 5 MB |
1 LB | 4 LB |
7 SL | 8 SU |
and the pattern is repeated for every set of 8 berths.
Tim and Bob are playing this game of finding the co-partner in a train of each berth. Write a program to do the same.
Input Format:
The input consists of an integer N, which corresponds to the berth number whose neighbor is to be found out.
Output Format:
The output is to display the berth of the neighbor of the corresponding seat.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to the output.]
Sample Input and Output 1:
1
4LB
Explanation:
1 corresponds to the 1LB, so the berth of the co-partner in the train will be 4LB.
Sample Input and Output 2:
5
2MB
Explanation:
5 corresponds to the 5MB, so the berth of the co-partner in the train will be 2MB.
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int coach = sc.nextInt(),temp,j=0;
temp = coach;
coach = coach/8;
int[] coachArray = new int[8];
if(temp%8==0){
for(int i=(coach-1)*8+1;i<=temp;i++)
{
coachArray[j]=i;
j++;
}
}
else{
for(int i = (coach*8)+1;i<=8*(coach+1);i++)
{
coachArray[j]=i;
j++;
}
}
if(coachArray[0]==temp)
System.out.println(coachArray[3]+"LB");
else if(coachArray[1]==temp)
System.out.println(coachArray[4]+"MB");
else if(coachArray[2]==temp)
System.out.println(coachArray[5]+"UB");
else if(coachArray[3]==temp)
System.out.println(coachArray[0]+"LB");
else if(coachArray[4]==temp)
System.out.println(coachArray[1]+"MB");
else if(coachArray[5]==temp)
System.out.println(coachArray[2]+"UB");
else if(coachArray[6]==temp)
System.out.println(coachArray[7]+"SU");
else if(coachArray[7]==temp)
System.out.println(coachArray[6]+"SL");
}
}
MOTIVATION :
“The way we spend our time defines who we are ”
Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.
VISITE MORE BLOGS