#include <stdio.h>
#define NUM 100
int max(int grade[], int n);
int min(int grade[], int n);
int main(void)
{
int i; int j; int n, x, y; char c; char code[n][NUM]; char name[n][NUM]; int grade[i]; scanf("%d", &n); for (i = 0; i != n; i++) { for (j = 0; ((int)(c = getchar())) != 32; j++) { name[i][j] = c; } for (j = 0; ((int)(c = getchar())) != 32; j++) { code[i][j] = c; } scanf("%d", &grade[i]); } x = max(grade, n); y = min(grade, n); printf("%s %s
%s %s
", name[x], code[x],name[y], code[y]); return 0;
}
int max(int *grade, int const n)
{
int tmp; tmp = grade[0]; int i = 1; int j = 1; while (i < n) { if (grade[i] > tmp){ tmp = grade[j]; i ++; j ++; } else { i ++; j ++; } } return j;
}
int min(int *grade, int const n)
{
int tmp; tmp = grade[0]; int i = 1; int j = 1; while (i < n) { if (grade[i] < tmp){ tmp = grade[j]; i++; j++; } else { i ++; j ++; } } return j;
}
max/min返回的int一定比grade数组的size大,然后printf会做成非法内存访问,依执行环境不同,可能崩溃或打印垃圾
一周热门 更多>