Which Fuel is Cheaper ( DSA INTERVIEW PREPARATION PROBLEMS AND SOLUTIONS )

 The current value of hydrocarbon is X rupees, and therefore the current value of diesel is Y rupees. At the beginning of every month, {the value|the worth|the value} of hydrocarbon will increase by A rupees and therefore the price of diesel will increase by B rupees.


Chef is curious to grasp that fuel prices less at the tip of the Kth month. If hydrocarbon is cheaper than diesel at the tip of Kth month, then print hydrocarbon. If diesel is cheaper than hydrocarbon at the tip of the Kth month, then print DIESEL. If each the fuels have identical value at the tip of the Kth month, then print SAME value.

Input Format
The first line of input contains one whole number T, denoting the amount of take a look at cases. the outline of T take a look at cases follows.
Each action at law consists of one line of input, containing 5 space-separated integers X,Y,A,B,K.
Output Format
For each action at law,

Print hydrocarbon if hydrocarbon is cheaper than diesel.
Print DIESEL if diesel is cheaper than hydrocarbon.
Print SAME value otherwise.
Note: The output is case-insensitive. you'll be able to print every character in either lower-case or upper-case.

Constraints
1≤T≤1000
1≤K≤1000
0≤X,Y,A,B≤1000
Subtasks
Subtask one (100 points): Original constraints
Sample Input one
3
1 1 1 1 1
2 1 2 1 2
2 2 1 1 2
Sample Output one
SAME PRICE
DIESEL
SAME PRICE
Explanation
Test case 1:

Initially, {the value|the worth|the value} of hydrocarbon is one rupee and therefore the price of diesel is one rupee. Since A=1 and B=1, the costs of each hydrocarbon and diesel increase by one rupee at the beginning of each month. So, at the beginning of the primary month, {the value|the worth|the value} of hydrocarbon becomes 1+1=2 rupees and therefore the price of diesel becomes 1+1=2 rupees. By the tip of the primary month, {the value|the worth|the value} of hydrocarbon and diesel area unit each two rupees and therefore they each have identical price.

Test case 2:

Initially, {the value|the worth|the value} of hydrocarbon is two rupees and therefore the price of diesel is one rupee. Since A=2 and B=1, {the value|the worth|the value} of hydrocarbon will increase by two rupee and therefore the price of diesel will increase by one rupee at the beginning of each month. It follows that at the beginning of the primary month, {the value|the worth|the value} of hydrocarbon becomes 2+2=4 rupees and therefore the price of diesel becomes 1+1=2 rupees. And by the beginning of the second month, {the value|the worth|the value} of hydrocarbon becomes 4+2=6 rupees and therefore the price of diesel becomes 2+1=3 rupees. By the tip of the second month, the costs of hydrocarbon and diesel area unit half dozen rupees and three rupees severally and therefore diesel is cheaper than hydrocarbon.

Test case 3:

Initially, {the value|the worth|the value} of hydrocarbon is two rupee and therefore the price of diesel is two rupee. Since A=1 and B=1, {the value|the worth|the value} of hydrocarbon will increase by one rupee and therefore the price of diesel will increase by one rupee at the beginning of each month. It follows that at the beginning of the primary month, {the value|the worth|the value} of hydrocarbon becomes 2+1=3 rupees and therefore the price of diesel becomes 2+1=3 rupees. And by the beginning of the second month, {the value|the worth|the value} of hydrocarbon becomes 3+1=4 rupees and therefore the price of diesel becomes 3+1=4 rupees. By the tip of the second month, costs|the costs} of hydrocarbon and diesel area unit each four rupees and therefore each have identical prices.

Code:

#include <iostream>
using namespace std;

int main() {
// your code goes here
int t;
cin >> t;
while(t--)
{
    int a, b, x, y, k, pet = 0, des = 0;
    cin >> a >> b >> x >> y >> k;
    pet = ((x*k)+a);
    des = ((y*k)+b);
    if(pet < des) cout <<"PETROL\n";
    else if(des < pet) cout <<"DIESEL\n";
    else cout << "SAME PRICE\n";
}
}

Previous
Next Post »