请问为什么全是wa,测试样例过了

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

NoThirtyFirst @ 2024-10-21 19:49:47

#include "bits/stdc++.h"

int n, k = 0;
double A, B = 0.0;
int Ai = 0; 
int Bi = 0;

int main()
{
    std::cin >> n;
    std::cin >> k;

    for(int i=1;i<=n; i++)
    {   
        if(i % k == 0)
        {
            A += i;
            Ai ++;
        } 
        else
        {
            B += i;
            Bi ++;
        }
    }
    std::printf("%.1f, %.1f", A/Ai, B/Bi);

    return 0;
}

by Yzmddsw @ 2024-10-21 19:54:10

@NoThirtyFirst 你为什么要输出逗号


by csq_OoO @ 2024-10-21 19:54:58

@NoThirtyFirst

std::printf("%.1f, %.1f", A/Ai, B/Bi);

多输出了逗号!!!


by NoThirtyFirst @ 2024-10-21 20:13:55

@csq_OoO wc没注意,感谢


by NoThirtyFirst @ 2024-10-21 20:14:16

@Yzmddsw wc没注意,感谢


by dingjingxuan1234 @ 2024-10-25 20:23:06

#include <bits/stdc++.h>
using namespace std;
int a[19];
int main(){
    long long n,a,h1=0,h2=0,c1=0,c2=0;
    cin>>n>>a;
    for(int i=1;i<=n;i++){
        if(i%a!=0){
            h1+=i;
            c1++;
        }else{
            h2+=i;
            c2++;
        }
    }
    printf("%.1f",h2*1.0/c2);
    cout<<" ";
    printf("%.1f",h1*1.0/c1);
}

|