对一串数据如果只是要求找出它的最大与最小值那我们可以利用两个变量对传入的每一组数据判断
并传下去。
如果非必须不必利用全排列。。。
例PAT1004https://pintia.cn/problem-sets/994805260223102976/problems/994805321640296448
参考代码:
#include <stdio.h> #include <string.h> int main() { int n=0; scanf("%d",&n); char name[11] ,max_name[11] ,min_name[11]; char hao[11],max_hao[11],min_hao[11]; int f=0,maxf=0,minf=100; for(int i=0;i<n;i++){ scanf("%s %s %d",name,hao,&f); if(f>=maxf){ maxf=f; strcpy(max_name,name);strcpy(max_hao,hao); } if(f<=minf){ minf=f; strcpy(min_name,name);strcpy(min_hao,hao); } } printf("%s %s\n",max_name,max_hao); printf("%s %s",min_name,min_hao); return 0; }