LMC314191 @ 2024-10-05 15:58:37
#include<stdio.h>
int main(){
int a[9999];
int n,k,m,change;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&m);
a[i]=m;
}
for(int k=0;k<n;k++){
for(int j=0;j<n-1;j++){
if(a[j]>a[j+1]){
change=a[j];
a[j]=a[j+1];
a[j+1]=change;
}
}
}
printf("%d",a[k]);
return 0;
}
by meifan666 @ 2024-10-05 16:03:01
@LMC314191
by Jerrycyx @ 2024-10-05 16:06:03
@LMC314191
int a[9999]
,而题目中 scanf("%d",&m); a[i]=m;
其实可以直接写成 scanf("%d",&a[i]);
的swap
,不过不用也行by Jerrycyx @ 2024-10-05 16:06:14
@LMC314191 求关
by LMC314191 @ 2024-10-05 16:17:45
@meifan666 @Jerrycyx 感谢大佬们