july lunch time div 3 chef and spell question :
question
#include<stdio.h>
int main(void) {
// your code goes here
int t;
int a,b,c,max=0;
scanf(“%d”,&t);
while(t–)
{
scanf(“%d %d %d”,&a,&b,&c);
if(a>b&&a>c)
{
if(c>b)
max=a+c;
else
max=a+b;
}
else if(b>a&&b>c)
{
if(a>c)
max=a+b;
else
max=b+c;
}
else if(c>a&&c>b)
{
if(a>b)
max=a+c;
else
max=b+c;
}
printf("%d\n",max);
}
return 0;
}
@skchefgg a,b,c, max ko long long int data type ka lena padega , because constraints are given that they are upto 10^18 and capacity of int is aprox 10^9 only.
while(t-)
this section of code is wrong …
make it
while(t–)
whole code :
#include<stdio.h>
int main() {
// your code goes here
int t;
int a,b,c,max=0;
scanf("%d",&t);
while(t–){
scanf("%d %d %d",&a,&b,&c);
if(a>b&&a>c)
{
if(c>b)
max=a+c;
else
max=a+b;
}
else if(b>a&&b>c)
{
if(a>c)
max=a+b;
else
max=b+c;
}
else if(c>a&&c>b)
{
if(a>b)
max=a+c;
else
max=b+c;
}
printf("%d\n",max);
}
return 0;
}
////////////////////////////////////////////////////////////////////
btw your code dosen’t give correct answer … check out mine c++ code for the logic mistake:
code------------------------
#include
typedef long long int ll;
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
ll t;
std::cin >> t;
while(t–){
ll count{0};
ll a,b, c;
std::cin >> a >> b>> c;
for( ll i : {1}){
if(a>=b && a>=c){
count +=a;
if(b>=c){
count += b;
break;
}else{
count +=c;
break;
}
}
if(b>=c && b>=a){
count +=b;
if(a>=c){
count +=a;
break;
}else{
count +=c;
break;
}
}
if(c>=a && c>=b){
count+=c;
if(a>=b){
count+=a;
break;
}else{
count +=b;
break;
}
}
}
std::cout << count << "\n";
}
return 0;
}
You did it hard way just subtract the minimum from the sum(a+b+c).
oh…thanks for this information.
will try that as well…thankyou
yeah…thanks for providing your code…I will rectify my error.
yes…i forgot to put a constraint for equal data…thanks for replying