零分求助

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

我安静存在 @ 2021-06-06 09:49:43

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double k,n,a,x=0,y=0,xx=0,yy=0,aa,bb;

    cin>>n>>k;
    for(a=k;a<=n;a=a+1){
        if(int(a)%int(k)==0){
            x=x+a;
            xx=xx+1;
        }
        else{
            y=y+a;
            yy=yy+1;
        }
    }
    aa=x/xx;
    bb=y/yy;
    printf("%.1lf %.1lf",aa,bb);
    return 0;
 } 

by AmaZingFantasy @ 2021-06-06 10:02:42

@我安静存在

把for循环的“a=k”改成“a=1”就行了


by 我安静存在 @ 2021-06-06 10:09:06

@安湛丰 谢谢!解决了!!!


|