why?

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

Jiangxh100315 @ 2024-09-09 23:04:37

#include<bits/stdc++.h>
using namespace std;
int n,k,cnt1=0,cnt2=0;
double ans1,ans2,sum1,sum2;

int main(){
    cin>>n;
    cin>>k;
    for(int i=1;i<=n;i++) {
        if(i%k==0){
            sum1+=i;
            cnt1++;
        }
        else{
            sum2+=i;
            cnt2++;

        }
        ans1=sum1/cnt1;
        ans2=sum2/cnt2;

        printf("%.1lf %.1lf",ans1,ans2);
        return 0;

    }
}

by sunhewei @ 2024-09-15 16:56:01

sum没有赋值为0


|