Car Trip Codechef Solution

Hello Programmers In this post, you will know how to solve the Car Trip Codechef Solution. The Problem Code is CARTRIP.

Car Trip Codechef Solution
Car Trip Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Problem

Chef rented a car for a day.

Usually, the cost of the car is Rs 10 per km. However, since Chef has booked the car for the whole day, he needs to pay for at least 300 kms even if the car runs less than 300 kms.

If the car ran X kms, determine the cost Chef needs to pay.

Ezoicreport this adInput Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of a single integer X – denoting the number of kms Chef travelled.

Output Format

For each test case, output the cost Chef needs to pay.

Constraints

  • 1 ≤ T ≤ 10
    1 ≤ X ≤ 1000

Sample 1

Input

5
800
3
299
301
300

8000
3000
3000
3010
3000

LinkedIn Skill Assessment Answers

Coursera Quiz Answers

Explanation:

Test case 11: The car runs for 800 kms. Thus, he needs to pay 800⋅10=8000 rupees.

Test case 22: The car runs for 3 kms. However, since Chef booked the car for whole day, he needs to pay for at least 300 kms. Thus, he needs to pay 300⋅10=3000 rupees.

Test case 33: The car runs for 299 kms. However, since Chef booked the car for whole day, he needs to pay for at least 300 kms. Thus, he needs to pay 300⋅10=3000 rupees.

Test case 44: The car runs for 301 kms. Thus, he needs to pay 301⋅10=3010 rupees.

Test case 55: The car runs for 300 kms. Thus, he needs to pay 300⋅10=3000 rupees.

Car Trip Codechef Solution in CPP

#include <bits/stdc++.h>
using namespace std;
int main(){
	int tc;
	cin>>tc;
	while(tc--){
		int X;
		cin>>X;
		if(X <= 300){
			cout<<"3000"<<"\n";
		}else{
			cout<<X * 10 <<"\n";
		}
	}
	return 0;
}
       

Car Trip Codechef Solutions 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
	{
		Scanner s=new Scanner(System.in);
		int T=s.nextInt();
		for(int i=0;i<T;i++)
		{
		    int X=s.nextInt();
		    if(X<300)
		    {
		        System.out.println(300*10);
		    }
		    else
		    {
		        System.out.println(X*10);
		    }
		}
	}
}

Car Trip Codechef Solution in Python

t = int(input())
for i in range(t):
    n = int(input())
    temp=n
    if n>300:
        temp= temp*10
        print(temp)
    else:
        print("3000")
    
Ezoicreport this ad

Disclaimer: The above Problem (Car Trip) is generated by CodeChef but the solution is provided by  BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Ticket Fine Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad