1.错误原因: 没有将变量设置为浮点型 2.做题思路: 将数据输入,写3个累加器将3个李白的喝酒量存进去,然后就可以开始打擂台,找出最大值后就开始找编号,最后输出。 更正代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
double a,b,c,d,e,x,y,maxx=INT_MIN,sum,sum1,sum2;
int main()
{
cin>>a>>b>>c>>d>>e>>x>>y;
sum=a*x+b*y;
sum1=c*y;
sum2=d*y+e;
if(sum>maxx)
{
maxx=sum;
}
if(maxx<sum1)
{
maxx=sum1;
}
if(maxx<sum2)
{
maxx=sum2;
}
if(sum==maxx)
{
cout<<1<<" "<<fixed<<setprecision(2)<<maxx;
return 0;
}
if(sum1==maxx)
{
cout<<2<<" "<<fixed<<setprecision(2)<<maxx;
return 0;
}
if(sum2==maxx)
{
cout<<3<<" "<<fixed<<setprecision(2)<<maxx;
return 0;
}
return 0;
}