Ticket Fine Codechef Solution

Hello Programmers In this post, you will know how to solve the Ticket Fine Codechef Solution. The Problem Code is TCKTFINE.

Ticket Fine Codechef Solution
Ticket Fine 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

On a certain train, Chef-the ticket collector, collects a fine of Rs. X if a passenger is travelling without a ticket. It is known that a passenger carries either a single ticket or no ticket.

PP passengers are travelling and they have a total of Q tickets. Help Chef calculate the total fine collected.

Input Format

The first line contains a single integer T, the number of test cases. T lines follow. Each following line contains three integers separated by spaces, whose description follows.

  • The first integer, X, is the fee in rupees.
  • The second integer, P, is the number of passengers on the train.
  • The third integer, Q, is the number of tickets Chef collected.

Output Format

The output must consist of T lines.

  • The ith line must contain a single integer, the total money(in rupees) collected by Chef corresponding to the ith test case.

Constraints

  • 1 ≤ T ≤ 10
    1 ≤ X ≤ 10
  • 0 ≤ QP ≤ 10

Sample 1:

Input

4
4 1 1
2 10 7
8 5 4
9 7 0

Output

0
6
8
63

LinkedIn Skill Assessment Answers

Coursera Quiz Answers

Explanation:

Test case 1: The total number of passengers travelling without ticket are 1 – 1 = 0. So the total fine collected is 0⋅4=0 rupees.

Test case 2: The total number of passengers travelling without ticket are 10−7=3. So the total fine collected is 3⋅2=6 rupees.

Test case 3: The total number of passengers travelling without ticket are 5−4=1. So the total fine collected is 1⋅8=8 rupees.

Test case 4: The total number of passengers travelling without ticket are 7−0=7. So the total fine collected is 7⋅9=63 rupees.

Ticket Fine Codechef Solution in CPP

#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int n,a,b,c;
    cin>>n;
    while (n--)
    {
        cin>>a>>b>>c;
        cout<<a*(b-c)<<endl;
    }
    return 0;
}
       

Ticket Fine 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 n=s.nextInt();
		for(int i=0;i<n;i++){
		    int x=s.nextInt();
		    int y=s.nextInt();
		    int z=s.nextInt();
		    if(y!=z){
		        System.out.println((y-z)*x);
		    }
		    else System.out.println("0");
		}
	}
}

Ezoicreport this adTicket Fine Codechef Solution in Python

# cook your dish here
t=int(input())
for i in range(t):
    x,p,q=map(int,input().split())
    z=p-q
    a=x*z
    print(a)
    
Ezoicreport this ad

Disclaimer: The above Problem (Ticket Fine) 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: Number of Credits Codechef Solution

Sharing Is Caring

Leave a Comment