Score High | Problem - 4 | Beginner level | C language | CodeChef
Link to the problem statement: https://www.codechef.com/submit-v2/HIGHSCORE
Solution:
1st Method:
#include <stdio.h>
int main(void) {
int t, i, n, a, b, c, d, s;
scanf("%d", &t);
for(i=0;i<t;i++)
{
if(t>=1 && t<=1000)
{
scanf("%d",&n);
scanf("%d %d %d %d", &a, &b, &c, &d);
s = a+b+c+d;
if( s == n && n>=a && n>=b && n>=c && n>=d )
{
if(a>=b && a>=c && a>=d)
{
printf("%d\n", a);
}
else if(b>=a && b>=c && b>=d)
{
printf("%d\n", b);
}
else if(c>=a && c>=b && c>=d)
{
printf("%d\n", c);
}
else
{
printf("%d\n", d);
}
}
}
}
return 0;
}
2nd Method:
#include <stdio.h>
int main(void)
{
int t, n, i, j, f, s, a[4];
scanf("%d", &t);
for(j=0;j<t;j++)
{
scanf("%d", &n);
for(i=0;i<4;i++)
{
scanf("%d", &a[i]);
}
s = a[0] + a[1] + a[2] + a[3];
if( s == n && a[0] <= n && a[1] <= n && a[2] <= n && a[3] <= n)
{
//finding the greatest
for(i=0;i<3;i++)
{
//swapping if greater
if(a[i] > a[i+1])
{
f = a[i];
a[i] = a[i+1];
a[i+1] = f;
}
else
continue;
}
printf("%d\n", a[3]);
}
}
return 0;
}
You can watch the video solution of this problem:
The video solution of this problem part b:
Hope this will help you, if you want anything else leave a comment.
Thank you
Comments
Post a Comment