C++98:二十个测试点居然全WA!求助

B2054 求平均年龄

__Harry_Haiyun__ @ 2023-06-02 22:19:36


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int temp;
    double sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> temp;
        sum += temp;
    }
    printf("%.2lf",sum / 2);
    return 0;
}

by cflsfzh @ 2023-06-02 22:23:08

???

sum / 2

by cflsfzh @ 2023-06-02 22:23:57

@Harry_Haiyun

平均年龄
sum/n

by ___Yang__ @ 2023-06-02 22:23:57

@Harry_Haiyun

AC代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int temp;
    double sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> temp;
        sum += temp;
    }
    printf("%.2lf", sum / n);//这里是除以 n
    return 0;
}

by C_Boa @ 2023-11-03 17:29:12

n/2???


|