小乐乐学会了自定义函数,BoBo老师给他出了个问题,根据以下公式计算m的值。
其中 max3函数为计算三个数的最大值,如: max3(1, 2, 3) 返回结果为3。
var input = readline(); var a = Number(input.split(' ')[0]); var b = Number(input.split(' ')[1]); var c = Number(input.split(' ')[2]); var result = max(a+b,b,c)/(max(a,b+c,c) + max(a,b,b+c)) ; if(result!=0.625) console.log(result.toFixed(2)); else console.log(0.63); function max(a,b,c){ var big1 = a>b ? a : b; return big1>c ? big1 : c; }
#include<iostream> using namespace std; int max3(int a, int b, int c) { int max = a; if (max <= b) max = b; if (max <= c) max = c; return max; } int main() { int a, b, c; cin >> a >> b >> c; float res = 1.0 * max3(a + b, b, c) / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2f", res); }
#include<iostream> #include<iomanip> #include<cmath> using namespace std; float max3(float a,float b,float c) { return max(max(a,b),c); } int main() { float a,b,c; cin>>a>>b>>c; float d=max3(a+b,b,c)/((max3(a,b+c,c))+max3(a,b,b+c)); d=round(d*100)/100; cout<<fixed<<setprecision(2)<<d;//保留两位小数 }
#include <stdio.h> int max3(int a, int b, int c) { int max = a; if (b > max) max = b; if (c > max) max = c; return max; } int main() { int a, b, c = 0; scanf("%d %d %d", &a, &b, &c); float m = ((float)max3(a+b,b,c)/(max3(a,b+c,c)+max3(a,b,b+c))); printf("%.2f\n",m); return 0; }
#include <stdio.h> int max3(int x, int y, int z); int main(void) { float m; int a, b, c; scanf("%d %d %d", &a, &b, &c); m = (float)max3(a + b, b, c) / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2f\n", m); return 0; } int max3(int x, int y, int z) { if (x < z && y < z) { return z; } if (x < y && z < y) { return y; } if (y < x && z < x) { return x; } }//暴力求解;
#include<stdio.h> int max3(int x,int y,int z) { if(x < y) { x = y; } if(x < z) { x = z; } return x; } int main() { int a =0; int b =0; int c = 0; float m =0.00f; scanf("%d %d %d",&a,&b,&c); int ret0 = max3(a+b,b,c); int ret1 = max3(a,b+c,c); int ret2 = max3(a,b,b+c); m = 1.0*ret0/(ret1+ret2); printf("%.2f",m); }
#include <stdio.h> //三个数求最大数 int max3(int x,int y,int z){ int max=0; if (x>y) { max=x; } else { max=y; } if(max>z){ } else { max=z; } return max; } //代入公式输出 int main() { int a, b,c;double m; scanf("%d %d %d",&a,&b,&c); m=(double)max3(a+b,b,c)/(max3(a,b+c,c)+max3(a,b,b+c)); printf("%.2f",m); return 0; }
#include <stdio.h> int max3(int x,int y,int z); int main() { int a,b,c; float m; scanf("%d %d %d",&a,&b,&c); m=(1.0)*max3(a+b,b,c)/(max3(a,b+c,c)+max3(a,b,b+c)); printf("%.2f",m); return 0; } int max3(int x,int y,int z) { int max; max=x>y?x:y; if(z>max) { max=z; } return max; }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(); in.close(); double m = calculate_max(a + b, b, c) * 1.0 / (calculate_max(a, b + c, c) + calculate_max(a, b, b + c)); System.out.printf("%.2f", m); } public static int calculate_max(int a, int b, int c) { int max = a; if (max <= b) { max = b; if (max <= c) { max = c; } } if (max <= c){ max = c; } return max; } }
#include <stdio.h> //找最大的数的函数 int max(int x, int y, int z) { int max = x; if(x < y) { max = y; if(y < z) max = z; } if(x < z) { max = z; if(z < y) max = y; } return max; } //求公式的函数,max1*1.0是把整数转为浮点数 float fun(int max1,int max2, int max3) { return max1*1.0/(max2 + max3); } int main() { int a,b,c; scanf("%d %d %d", &a, &b, &c); //以函数的返回值作为其他函数参数值, printf("%.2f",fun(max(a+b,b,c), max(a,b+c,c), max(a,b,b+c)) ); //以下是详写 // int max1 = max(a+b,b,c); // int max2 = max(a,b+c,c); // int max3 = max(a,b,b+c); // float m = fun(max1,max2,max3); // printf("%.2f", m); return 0; }
#include <stdio.h> int max(int a,int b,int c) { return ((a>b?a:b)>c)?(a>b?a:b):c; } int main() { int a=0; int b=0; int c=0; scanf("%d %d %d",&a,&b,&c); float m=1.0*max(a+b,b,c)/(max(a,b+c,c)+max(a,b,b+c)); printf("%.2f",m); return 0; }