Codechef : Problem name "Better Deal" solution in C#
=====================Solution code in C#=====================
using System;
public class Test
{
public static void Main()
{
int t=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<t;i++){
string[] array=Console.ReadLine().Split(' ');
int A=Convert.ToInt32(array[0]);
int B=Convert.ToInt32(array[1]);
int discountedprice_store1=100-A;
int discountedprice_store2=200-B*2;
if(discountedprice_store1<discountedprice_store2){
Console.WriteLine("First");
}
else if(discountedprice_store2<discountedprice_store1)
Console.WriteLine("Second");
else if(discountedprice_store1==discountedprice_store2)
Console.WriteLine("Both");
}
}
}
we are calculating discounted price for store 1: (original price) -( (discount/100) * (original price) ) hence 100-(A/100)*100 ------> 100 - A
for store 2 : (original price) -( (discount/100) * (original price) ) hence 200 - (B/100)200 ------------> 200 - 2B
Comparing and printing the value which store is giving more discount in price
Comments
Post a Comment