帮帮忙

P5719 【深基4.例3】分类平均

chenkuo @ 2022-05-03 17:32:16

我的代码怎么才40分,大佬们帮帮忙,谢谢

#include<bits/stdc++.h>
using namespace std;
int n,k,a,b,sa,sb;
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        if(i%k==0) a+=i,sa++;
        else b+=i,sb++;
    }
    printf("%.1lf %.1lf",(double)(a/sa),(double)(b/sb));
}

by AfterFullStop @ 2022-05-03 17:35:39

申明变量时直接用double就没问题了


by Jason12 @ 2022-05-03 17:36:35

@chenkuochenkuo 样例没过,应该输出 56.0 50.1,但你的代码输出56.0 50.0


by Jason12 @ 2022-05-03 17:37:56

@chenkuochenkuo 输出部分改成printf("%.1lf %.1lf",(double)(a*1.0/sa),(double)(b*1.0/sb));


by chenkuo @ 2022-05-03 18:00:43

@Jason12 @LemonAndMelon 谢谢


|