Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Packing Books CodeChef Solution

Problem – Packing Books CodeChef Solution

Chef is moving to a new house!

Unfortunately, this means he now has to pack up his things so that they can be moved too. Currently, Chef is packing up his (rather impressive) book collection into cardboard boxes.

Chef has X shelves of books, each of which contains exactly Y books. Each cardboard box can hold at most Z books. In order to not mess up the organization of the books, Chef will also ensure that books from different shelves will not be placed in the same box.

Under these conditions, what is the minimum number of boxes needed to pack all the books?

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of one line of input, containing three space-separated integers X, Y, and Z: the values described in the statement.

Output Format

For each test case, output on a new line one integer: the minimum number of boxes needed to pack all the books.

Constraints

  • 1 \leq T \leq 10001≤T≤1000
  • 1 \leq X, Y, Z \leq 10001≤X,Y,Z≤1000

Sample 1:

Input: 
4
5 9 9
5 9 7
2 3 2
22 34 12
Output: 
5
10
4
66

Explanation:

Test case 1: Each box can hold 9 books, and each shelf has 9 books. So, Chef needs only five boxes: one for each shelf.

Test case 2: Each box can hold 7 books, and each shelf has 9 books. So, Chef needs two boxes to hold all the books of one shelf (for example, one holding 4 books and another one holding 5). There are five shelves, so the total number of boxes needed is 5×2=10.

Test case 3: Each box can hold 2 books, and each shelf has 3 books. So, Chef needs two boxes to hold all the books of one shelf (for example, one holding 22 books and another one holding 1). There are two shelves, so the total number of boxes needed is 2×2=4.

Test case 4: Each shelf needs 33 boxes to pack all its books. There are 22 shelves, so the answer is  2×3=6.

Packing Books CodeChef Solution in Python3

# cook your dish here
for _ in range(int(input())):
    x,y,z=map(int,input().split())
    k=0
    if y%z==0:
        k=y//z
    else:
        k=(y//z)+1 
    print(x*k)
        

Packing Books CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	
	
	while(t--)
	{
	    int c=1;
	    int x,y,z;
	   
	    cin>>x>>y>>z;
	    
	  while(y>z){
	      y=y-z;
	      c++;
	  }
	  
	  cout<<x*c<<endl;
	   
	}
	return 0;
}

Packing Books CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0){
		    int a=sc.nextInt();
		    int b=sc.nextInt();
		    int c=sc.nextInt();
		    if (c>=b){
		        System.out.println(a);
		    }
		    else{
		        if(b%c==0){
		            System.out.println(a*(b/c));
		        }
		        else{
		            System.out.println(a*(b/c+1));
		        }
		    }
		    
		}
	}
}
Packing Books CodeChef Solution Review:

In our experience, we suggest you solve this Packing Books CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Packing Books CodeChef Solution

Find on CodeChef

Conclusion:

I hope this Packing Books CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *