参考代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> //构建交换函数 void swap(int *a, int * b) { int temp = 0; temp = a[0]; a[0] = b[0]; b[0] = temp; temp = a[1]; a[1] = b[1]; b[1] = temp; temp = a[2]; a[2] = b[2]; b[2] = temp; } int main() { int n = 0; scanf("%d", &n); int number[n][3]; for (int i = 0; i < n; ++i) { for (int j = 0; j < 3; ++j) { scanf("%d", &number[i][j]); } } int point = 0; scanf("%d", &point); //开始排序 for (int i = 0; i < n - 1; ++i) { for (int j = i + 1; j < n; ++j) { //先处理第一个数字 if (number[j][0] < number[i][0]) { swap(&number[j][0], &number[i][0]); continue; } else if (number[j][0] == number[i][0]) {//第一个数字相同,那就看第二个数字 if (number[j][1] < number[i][1]) { swap(&number[j][0], &number[i][0]); continue; } else if (number[j][1] == number[i][1]) {//第二个数字相同,那就看低三个数字 if (number[j][2] < number[i][2]) { swap(&number[j][0], &number[i][0]); } } } } } //打印输出一下排序结果 for (int i = 0; i < 3; ++i) { printf("%d ", number[point - 1][i]); } }
0.0分
3 人评分