#include <stdio.h> #include <stdlib.h> int cmp(const void *a,const void *b) { return (*(int *)a-*(int *)b); } int main() { int n,arr[10001],i; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } qsort(arr,n,sizeof(arr[0]),cmp); printf("%d",arr[n / 2]); return 0; }
find the median amount of milk given such that at least half the cows give the same amount of milk or more and at least half give the same or less.
一列数排序过后(奇数个),最中间的数一定是大于或等于左边的数,最中间的数一定是小于或者等于右边的数,而且两边各一半
时间: 2024-10-09 08:17:36