90分求助

B2088 计算书费

LBlue @ 2023-04-23 21:40:34

测试点 #5 WA,请问是不能用两个数组吗

#include<iostream>
using namespace std;
int main()
{
    int book[10];
    double t = 0,a[10] = {28.9,32.7,45.6,78,35,86.2,27.8,43,56,65};
    for(int i = 0;i < 10;i++)
        cin >>book[i];
    for(int i = 0;i < 10;i++)
        t+=book[i] * a[i];
    cout << t << endl;
    return 0;
}

麻烦各位帮忙看一下,谢谢!


by SamHJD @ 2023-04-23 21:48:01

#include<iostream>
using namespace std;
int main()
{
    int book[10];
    double t = 0,a[10] = {28.9,32.7,45.6,78,35,86.2,27.8,43,56,65};
    for(int i = 0;i < 10;i++)
        cin >>book[i];
    for(int i = 0;i < 10;i++)
        t+=book[i] * a[i];
    printf("%.1lf",t);
    return 0;
}

若答案为整数也需保留一位小数,%.xlf就是保留 x 位小数的意思


by LBlue @ 2023-04-23 21:58:52

@SamHJD 知道啦,谢谢!


|