My issue
My code
// Update the code below to solve the problem
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int X,Y;
cin>>X>>Y;
if(3*X==2*Y)
cout<<X<<endl;
if(3*X>2*Y)
cout<<X<<endl;
if(3*X<2*Y)
cout<<Y<<endl;
}
return 0;
}
Learning course: Solve Programming problems using C++
Problem Link: CodeChef: Practical coding for everyone
@sinhasadhana95
U have to print the smaller cost value
i have corrected it in your code hope u will get it.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int X,Y;
cin>>X>>Y;
if(3*X==2*Y)
cout<<3*X<<endl;
if(3*X>2*Y)
cout<<2*Y<<endl;
if(3*X<2*Y)
cout<<3*X<<endl;
}
return 0;
}
They have asked to print the total cost. But you just print the cost of one room. You got the logic right but just the printing part (Also check a simpler solution below)
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int X, Y;
cin >> X >> Y;
if(3 * X == 2 * Y)
cout << 3 * X << "\n"; // or can also print 2 * Y
else if (3 * X < 2 * Y)
cout << 3 * X << "\n";
else
cout << 2 * Y << "\n";
}
return 0;
}
You can also do it in one line. They asked to print the minimum cost of the rooms. So you just need the minimum of 3* X and 2 * Y
. So you can simply do it this way.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int X, Y;
cin >> X >> Y;
cout << min(3 * X, 2 * Y) << "\n";
}
return 0;
}