wzy_ok @ 2024-11-29 22:03:54
差不多的代码怎么一个40分一个100分?
100分:
#include<bits/stdc++.h>
using namespace std;
int x[5000005],k;
int main()
{
int n;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++)scanf("%d",&x[i]);
sort(x,x+n);
printf("%d",x[k]);
return 0;
}
40分:
#include<bits/stdc++.h>
using namespace std;
int n,k,a[5000005];
int main() {
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);
printf("%d",a[k]);
return 0;
}
by wzy_ok @ 2024-11-29 22:04:38
不对吗???
by Alex_smy @ 2024-11-29 22:06:39
下标一个从 printf("%d",a[k]);
应改为 printf("%d",a[k+1]);
(我也没仔细看,猜的)
by wzy_ok @ 2024-11-29 22:08:33
没看懂你写的
by wzy_ok @ 2024-11-29 22:14:35
不过一改倒是对了(已关注)。
by yoeklung @ 2024-12-05 13:12:47
@wzy_ok 注意题目“