大佬们帮我看看这个问题出现在哪

P5726 【深基4.习9】打分

``` y=a[2]; a[2]=a[i]; a[2]=y; ``` 应该是 ``` y=a[2]; a[2]=a[i]; a[i]=y; ```
by Henry2012 @ 2023-04-17 13:12:11


@[sy1234567887](/user/965878) 已经改好了,求关注 ```cpp #include <bits/stdc++.h> #define MAXN 1000 using namespace std; int n; int s; int a[MAXN + 5]; inline int read() { int x = 0, y = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') y = -1; c = getchar(); } while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * y; } int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); //大概明白你的意思了,以a[1]为max,a[2]为min,但是过于复杂了,在比赛中容易TLE,把a[3]之后的加起来 for (int i = 2; i <= n; i++) if (a[i] > a[1]) swap (a[i], a[1]);//swap函数可以直接将两个数交换数值看,之前的判断是反的 for (int i = 2; i<=n; i++) if (a[i] < a[2]) swap (a[i], a[2]); for (int i = 3; i <= n; i++) s += a[i]; printf("%.2lf",double (s * 1.0 / (n - 2))); return 0; } ```
by Score_Elevate @ 2023-09-01 20:33:51


|