HDOJ 1029 Ignatius and the Princess IV

来源:互联网 发布:underscore.js 使用 编辑:程序博客网 时间:2024/04/30 19:25

原题链接

快排后取中间那个数。

附ac代码:

#include <stdio.h>#include <stdlib.h>int cmp(const void *a, const void *b){return *(int *)a - *(int *)b;}int main(){int n, *a, i;while(scanf("%d", &n) == 1){i = n;a = (int *)malloc(sizeof(int) *n);while(i--)scanf("%d", &a[i]);qsort(a, n, sizeof(int), cmp);printf("%d\n", a[n / 2]);free(a);}return 0;}


0 0