题解 | #找最小数#
找最小数
https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd
#include <stdio.h> #include <stdlib.h> typedef struct nums{ int x; int y; }NUMS; int cmp(const void*a,const void*b){ if(((NUMS *)a)->x == ((NUMS *)b)->x){ return ((NUMS *)a)->y > ((NUMS *)b)->y; } return ((NUMS *)a)->x > ((NUMS *)b)->x; } int main() { int n; while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case NUMS arr[n]; for(int i=0;i<n;++i){ scanf("%d %d",&arr[i].x, &arr[i].y); } qsort(arr,n,sizeof(NUMS),cmp); printf("%d %d",arr[0].x,arr[0].y); } return 0; }