求助,Dev上没问题,5个WA

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

liboya5074 @ 2023-11-25 09:22:23

Dev-c++上可以啊

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

为什么啊?


by zhangbo1000 @ 2023-11-25 09:41:07


by chillLee @ 2023-11-25 09:43:03

您不妨把变量都放在主函数外边


by liboya5074 @ 2023-11-25 10:04:16

谢谢!!!


by liboya5074 @ 2023-11-25 10:08:05

二位真的是dalao


|