题解 | #找最小数#
找最小数
https://www.nowcoder.com/practice/ba91786c4759403992896d859e87a6cd
#include <cstdio> int main() { int n; scanf("%d\n",&n); int arr[n][2]; for(int i=0;i<n;i++){ scanf("%d%d",&arr[i][0],&arr[i][1]); } int min_x=arr[0][0],min_y=arr[0][1]; for(int i=0;i<n;i++){ if(arr[i][0]>min_x) continue; else if(arr[i][0]==min_x&&arr[i][1]<min_y){ min_y=arr[i][1]; } else if(arr[i][0]<min_x){ min_x=arr[i][0]; min_y=arr[i][1]; } else continue; } printf("%d %d\n",min_x,min_y); return 0; }
用一个2维数组存x,y的值,再用for遍历找最小xy输出就可以
用一个min_x和min_y记录最小x和最小y,然后输出就可以了