小乐乐学会了自定义函数,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> float max3(int a, int b, int c) { int nums[3]; nums[0] = a; nums[1] = b; nums[2] = c; int max = nums[0]; int i = 0; for (i = 1; i < 3; i++) { if (max < nums[i]) { max = nums[i]; } } return max; } int main() { int a = 0; int b = 0; int c = 0; float m = 0.0f; scanf("%d %d %d", &a, &b, &c); m = (max3(a + b, b, c)) / (max3(a, b + c, c) + max3(a, b, b + c)); printf("%.2f\n", m); return 0; }因为是确定的三个数,可以定义3个数的数组然后放入,再进行比大小
#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; } }