In this Discus Throw problem, a player is given 3 throws and the throw with the longest distance is counted as the final score of the player. we have given the distance for all 3 throws of a player and we need to determine the final score of the player.
Let's say the player throws the disc three times and the longest distance is achieved in the second throw is 15. so the score of the player is 15.
Problem solution in C programming.
#include <stdio.h>
int main(void) {
int t,i;
scanf("%d",&t);
for(i=0;i<t;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(a>=b&&a>=c)
{
printf("%d\n",a);
}
else if(b>=a&&b>=c)
{
printf("%d\n",b);
}
else
{
printf("%d\n",c);
}
}
// your code goes here
return 0;
}
Here in the above code first we declare two variables t and i. and after that, we are scanning the number of test cases given by the user and store it in the t variable. after that in the for loop, we are declaring the three variables to read the scores of a person that he can score after throwing the disc three times. after that, we are checking if the value of a is greater than b and also greater than c then it will be the highest score of the user and should be the final score of the user. if not then we are checking if the value of b is greater than a and also from c then it will be the final score of the user. and if not then definitely the value of c is the highest score of the person. so it will be the final score.
Problem solution in C++ programming.
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t,a,b,c;
cin>>t;
while(t--)
{
cin>>a>>b>>c;
if(a>=b && a>=c)
cout<<a<<"\n";
else if(b>=c)
cout<<b<<"\n";
else
cout<<c<<"\n";
}
return 0;
}
Problem solution in Java programming.
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int i=0;i<T;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int score= a>b?(a>c?a:c):(b>c?b:c);
System.out.println(score);
}
}
}
Problem solution in Python programming.
# cook your dish here for _ in range(int(input())): l=list(map(int,input().split())) print(max(l))
Here in the above logic, we are using a different approach. in the for loop itself, we are taking input from the user for which the for loop is running for the number of the test cases. after that, we are using the l variable to get the number of scores that a man-made in their every throw. and we are storing it as a list in the l variable. and then simply we are finding the maximum value in the list. that is the highest score of the person.
0 Comments