信息学奥赛一本通 1152:最大数max(x,y,z)
生活随笔
收集整理的這篇文章主要介紹了
信息学奥赛一本通 1152:最大数max(x,y,z)
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
【題目鏈接】
ybt 1152:最大數(shù)max(x,y,z)
【題目考點(diǎn)】
1. 函數(shù)
2. max函數(shù)
<algorithm>中有max函數(shù),參數(shù)可以是兩個(gè)整形量,可以是兩個(gè)浮點(diǎn)型量,求兩個(gè)量中的較大值。
【題解代碼】
解法1:自己設(shè)求三個(gè)數(shù)字最大值的函數(shù)
#include<bits/stdc++.h> using namespace std; //求a,b,c三個(gè)數(shù)中的最大值 double Max(double a, double b, double c) {if(a >= b && a >= c)return a;else if(b >= a && b >= c)return b;elsereturn c; }int main() {double a, b, c;cin >> a >> b >> c;cout << fixed << setprecision(3) << Max(a, b, c) / (Max(a + b, b, c) * Max(a, b, b + c));return 0; }解法2:使用<algorithm>中的max函數(shù)
#include<bits/stdc++.h> using namespace std; int main() {double a, b, c;scanf("%lf %lf %lf", &a, &b, &c);printf("%.3f", max(max(a, b), c) / (max(a+b, max(b, c)) * max(a, max(b, b+c))));return 0; }總結(jié)
以上是生活随笔為你收集整理的信息学奥赛一本通 1152:最大数max(x,y,z)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: atom 快速编写html,Atom 编
- 下一篇: 二维随机变量期望公式_概率论笔记-Ch4