Chef and the Hair Salon Solution Codechef

Chef and the Hair Salon Solution Codechef

Chef recently realized that he needs a haircut, and went to his favorite hair salon. At the salon, he found NN customers waiting for their haircuts. From his past experience, Chef knows that the salon takes MM minutes per customer. Only one person can get their haircut at a time.

For how many minutes will Chef have to wait before he can get his haircut?

Input Format

  • The first line of input contains a single integer TT, denoting the number of test cases. The description of TT test cases follows.
  • The first and only line of each test case contains two space-separated integers NN and MM, as described in the problem.

Output Format

For each test case, print a single line containing one integer — the number of minutes that Chef will have to wait before he can get his haircut.

Constraints

  • 1≤T≤10001≤T≤1000
  • 0≤N≤10000≤N≤1000
  • 1≤M≤10001≤M≤1000

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1 

2
2 15
0 15

Sample Output 1 

30
0

Explanation

Test case 11: There are 22 customers waiting for the haircut and the salon will take 1515 minutes for each customer, hence Chef will have to wait for 3030 minutes before he can get his haircut.

Test case 22: There are 00 customers waiting for the haircut, therefore the Chef will not have wait to get the haircut.

Chef and the Hair Salon Solution Codechef
Chef and the Hair Salon Solution Codechef

SOLUTION

Program: Chef and the Hair Salon Solution in Python

for _ in range(int(input())):
    a,b=map(int,input().split())
    if a>0:
        print(a*b)
    else:
        print(a)

Program: Chef and the Hair Salon Solution in C++

#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--)
	{
	   int n,m;
	   cin>>n>>m;
	   cout<<(n*m)<<endl;
	}
	return 0;
}

Program: Chef and the Hair Salon Solution in Java

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	   
	    Scanner sc= new Scanner(System.in);
	    int t=sc.nextInt();
	    
	    for(int i=0;i<t;i++)
	    {
	    int a=sc.nextInt();
	    int b=sc.nextInt();
	    
	    if (a!=0)
	    {
	        System.out.println(a*b);
	    }
	    else{
	        System.out.println(a);
	    }
	    }
	}
}

February Long Challenge 2022 Solution

January Long Challenge 2022 Solution

Leave a Comment

19 − fourteen =