我不理解
查看原帖
我不理解
853903
Ishr_Mla楼主2023/2/6 09:14

为什么初始化max = 0会AC,初始化max = -1000000反而会在第一个点WA??

代码如下

#include <stdio.h>

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int T, n;
    scanf("%d", &T);
    int max = 0, cnt = 1, ans = 0;
    while (T--)
    {
        scanf("%d", &n);
        if (n == max)
            cnt++;
        else if (n > max)
        {
            max = n;
            cnt = 1;
        }
        ans += n;
    }
    ans -= max * cnt;
    printf("%d", ans);
    return 0;
}
2023/2/6 09:14
加载中...