爆0求助!

B2088 计算书费

CSP_AK_xyy20110721 @ 2022-08-18 13:59:04


#include<iostream>
using namespace std;
int main()
{
    int a[11],i,s;
    for(i=1;i<=10;i++)
    {
        cin>>a[i];

    }
    a[1]*=28.9;
    a[2]*=32.7;
    a[3]*=45.6;
    a[4]*=78;
    a[5]*=35;
    a[6]*=86.2;
    a[7]*=27.8;
    a[8]*=43;
    a[9]*=56;
    a[10]*=65;
    printf("%.1f",a[10]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);
    return 0;
}

by Murasoishi @ 2022-08-18 14:00:39

@xyy20110721 a数组应为double类型


by ISTP @ 2022-08-18 14:01:02

数组要开float或double类型的,不然算好的小数存进去小数位会自动舍弃掉


by w15998366226 @ 2022-08-18 14:03:14

开double类型数组


by CSP_AK_xyy20110721 @ 2022-08-18 14:05:04

哦对!!!鄙人忘啦!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


by CSP_AK_xyy20110721 @ 2022-08-18 14:08:17

但是......

1

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 3. 3ms/712.00KB WA

2

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 2. 3ms/788.00KB WA

3

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 2. 4ms/696.00KB WA

4

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 1. 3ms/680.00KB WA

5

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 3. 3ms/680.00KB WA

6

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 2. 3ms/692.00KB WA

7

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 3. 3ms/800.00KB WA

8

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 3. 3ms/684.00KB WA

9

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 2. 3ms/684.00KB WA

10

Wrong Answer.wrong answer On line 1 column 1, read 0, expected 2.


by ben090302 @ 2022-08-18 14:10:58

@xyy20110721 拿你的改的,A了


#include<iostream>
using namespace std;
int main()
{
    double a[11];
    int i,s;
    for(i=1;i<=10;i++)
    {
        cin>>a[i];

    }
    a[1]*=28.9;
    a[2]*=32.7;
    a[3]*=45.6;
    a[4]*=78;
    a[5]*=35;
    a[6]*=86.2;
    a[7]*=27.8;
    a[8]*=43;
    a[9]*=56;
    a[10]*=65;
    printf("%.1f",a[10]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]);
    return 0;
}

by 2_202240210224 @ 2023-06-08 13:13:37

这是我的AC代码,简单粗暴,不用动脑:

#include<bits/stdc++.h>
using namespace std;

int main(){
    int arr[10];
    double sum=0;
    for(int i=0;i<10;i++){
        cin>>arr[i];
        if(i==0){
            sum+=28.9*arr[i];
        } 
        else if(i==1){
            sum+=32.7*arr[i]; 
        }
        else if(i==2){
            sum+=45.6*arr[i];
        }
        else if(i==3){
            sum+=78*arr[i];
        }
        else if(i==4){
            sum+=35*arr[i];
        }
        else if(i==5){
            sum+=86.2*arr[i];
        }
        else if(i==6){
            sum+=27.8*arr[i];
        }
        else if(i==7){
            sum+=43*arr[i];
        }
        else if(i==8){
            sum+=56*arr[i];
        }
        else if(i==9){
            sum+=65*arr[i];
        }

    }
    printf("%.1lf",sum);
    return 0;
}

|