Hello coders, today we are going to solve the Car Trip Codechef Solution whose Problem Code is CARTRIP.
As you already know that this site does not contain only the Codefchef solutions here, you can also find the solution for other programming problems. I.e. Leetcode, C programs, C++ Programs Solutions, Python Programs, Web Technology, Data Structures, RDBMS Programs and Java Programs Solutions.

Car Trip Codechef Solution
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.
Input 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 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 { 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")
Disclaimer: The above Problem (Car Trip) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.
Finally, we are now, in the end, I just want to conclude some important message for you
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.
Please share our posts on social media platforms and also suggest to your friends to Join Our Groups. Don’t forget to subscribe.