Problem - Vehicles and Wheels
An automobile company manufactures both a two wheeler (TW) and a four wheeler (FW). A company manager wants to make the production of both types of vehicle according to the given data below:
- 1st data, Total number of vehicle (two-wheeler + four-wheeler) = V
- 2nd data, Total number of wheels = W
The task is to find how many two-wheelers as well as four-wheelers need to manufacture as per the given data.
Example:
Input:
Output:
Explanation:
Input:
200 -> Value of V 540 -> Value of W Output:
TW=130 FW=70
130+70 = 200 vehicles(70*4)+(130*2)= 540 wheels
- 2<=W
- W%2=0
- V<W
Print "INVALID INPUT", if inputs did not meet the constraints.
Input Format
The candidate has to write the code to accept two positive numbers separated by a new line.
First Input line - Accept value of V.
Second Input line - Accept value for W.
Output Format
Written program code should generate two outputs, each separated by a single space character
NOTE: Additional messages in the output will result in the failure of test case
The candidate has to write the code to accept two positive numbers separated by a new line.
First Input line - Accept value of V.
Second Input line - Accept value for W.
Output Format
Written program code should generate two outputs, each separated by a single space character
NOTE: Additional messages in the output will result in the failure of test case
Problem Overview:
The program calculates the exact number of two-wheelers and four-wheelers given:
- Input: Two integers representing total vehicles (
noOfVehicles) and total wheels (noOfWheels). - Validation Rules: The total wheels must be at least 2, must be an even number, and cannot be less than the number of vehicles. Otherwise, output
INVALID INPUT.
Mathematical Approach
Let's define the variables used in the equations:
- V = Total vehicles (
noOfVehicles) - W = Total wheels (
noOfWheels) - T = Number of two-wheelers
- F = Number of four-wheelers
We set up a system of linear equations based on the constraints:
1) T + F = V → F = V - T
2) 2T + 4F = W
2) 2T + 4F = W
Substituting equation (1) into equation (2):
2T + 4(V - T) = W
2T + 4V - 4T = W
4V - 2T = W
T = (4V - W) / 2
2T + 4V - 4T = W
4V - 2T = W
T = (4V - W) / 2
Once T (two-wheelers) is found, the number of four-wheelers F is derived simply as: F = V - T.