2840: 编程题AB-面粉质量差

来源:互联网 发布:手机陀螺仪水平仪软件 编辑:程序博客网 时间:2024/06/08 12:09

2840: 编程题AB-面粉质量差

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 109  Solved: 35
[Submit][Status][Web Board]

Description

某粮店出售的三种品牌的面粉袋上,分别标有质量为(m1±e1)㎏,(m2±e2)㎏,(m3±e3)㎏的字样,从中任意拿出两袋,它们的质量最多相差多少?

Input

 m1,e1,m2,e2,m3,e3(输入包含多组数据,每组一行)

Output

最大质量差(结果保留一位小数)

Sample Input

5 0.1 10 0.2 15 0.310 0.9 10 0.5 10 0.6

Sample Output

10.41.8

HINT

Source

lyh

代码:

#include <iostream>#include <iomanip>using namespace std;int main(){    double m1,e1,m2,e2,m3,e3,max,min;    while(cin>>m1&&m1>0)    {        cin>>e1>>m2>>e2>>m3>>e3;        max=m1+e1;        min=m1-e1;        if(max<m2+e2)            max=m2+e2;        if(max<m3+e3)            max=m3+e3;        if(min>m2-e2)            min=m2-e2;        if(min>m3-e3)            min=m3-e3;      cout<<setiosflags(ios::fixed)<<setprecision(1)<<max-min<<endl;    }    return 0;}


运行结果:

学习心得:
上学期想复杂了的题,上学期我一看到就想到数组各种比较,然后自己把自己绕晕了,今天无意间看到这道题,再做发现真的好简单...我在想当时我在想什么...唉

0 0
原创粉丝点击