Three real
numbers õ, y and z are given. Find min(max(x, y), max(y,
z), x + y + z) using the auxiliary
functions for calculation the minimum and the maximum of two elements.
Input. Three real numbers õ, ó and z are given in one line. Their values do not
exceed 100 by absolute value.
Output. Print the
answer with two decimal digits.
Sample
input |
Sample
output |
1.05 2.25
2.15 |
2.25 |
functions
Define the functions minimum and maximum of two numbers. Using
them compute the required expression.
Algorithm realization
Define
the functions minimum min and
maximum max of two numbers.
double min(double
x, double y)
{
return (x
< y) ? x : y;
}
double max(double
x, double y)
{
return (x
> y) ? x : y;
}
The main part of the program. Read the input data. Compute and print the
answer.
scanf("%lf %lf %lf",&x,&y,&z);
res =
min(min(max(x,y),max(y,z)),x+y+z);
printf("%.2lf\n",res);
Java
realization
import java.util.*;
public class Main
{
public static void main(String[]
args)
{
Scanner con = new
Scanner(System.in);
con.useLocale(Locale.US);
double x = con.nextDouble();
double y = con.nextDouble();
double z = con.nextDouble();
double res = Math.min(Math.min(Math.max(x,y),
Math.max(y,z)), x + y + z);
System.out.println(res);
con.close();
}
}
Java
realization – functions
import java.util.*;
public class Main
{
public static double min(double x, double y)
{
return (x <
y) ? x : y;
}
public static double max(double x, double y)
{
return (x >
y) ? x : y;
}
public static void
main(String[] args)
{
Scanner con = new
Scanner(System.in);
double x = con.nextDouble();
double y = con.nextDouble();
double z = con.nextDouble();
double res = min(min(max(x,y), max(y,z)), x + y + z);
System.out.println(res);
con.close();
}
}
Python realization
x, y, z = map(float, input().split())
res = min(min(max(x, y), max(y, z)), x + y + z);
print(res)