数不对

B2088 计算书费

Jiangxh100315 @ 2024-03-28 14:27:33

#include<bits/stdc++.h>
using namespace std;
float js=28.9,sj=32.7,sz=45.6,c=78,r=35,jg=86.2,by=27.8,cz=43,wl=56,ja=65;
int main(){
    int a,b,c2,d,e,f,z,r,t,q;
    cin>>a>>b>>c2>>d>>e>>f>>z>>r>>t>>q;
    float a1=a*js,b1=b*sj,c1=sz*c2,d1=c*d,e1=r*e,f1=jg*f,z1=by*z,r1=cz*r,t1=wl*t,q1=ja*q;
    float x1=a1+b1+c1+d1+e1+f1+z1+r1+t1+q1;
    cout<<fixed<<setprecision(1)<<x1;
    return 0;
}

by Curry_mvp @ 2024-03-28 14:28:44

·····这道题用数组不香吗?


by Curry_mvp @ 2024-03-28 14:32:07

#include<bits/stdc++.h>
using namespace std;
double a[11]={0,28.9,32.7,45.6,78,35,86.2,27.8,43,56,65};
int main()
{
    int m;
    double sum=0;
    for(int i=1;i<=10;i++)
    {
        cin>>m;
        sum+=1.0*m*a[i];
    }
    cout<<fixed<<setprecision(1)<<sum<<"\n";
    return 0;
}

|