#include#include#includetypedef struct stu{ int sno; int grade; }STU,*stu; int main(){ int n,m; int status=scanf("%d", &n); status=scanf("%d", &m); //直接开辟m+n的链表,报两个值加进去 stu s = (stu)malloc(sizeof(STU) * (m + n)); if(s != NULL){ for(int i = 0; i < m + n; i++){ status = scanf("%d", &(s + i)->sno); status = scanf("%d", &(s + i)->grade); /*printf("%d", (s + i)->sno); printf("%d", (s + i)->grade);*/ } int min_index = 0; int min = 0; for(int i = 0; i < m + n - 1; i++){ min_index = i; min = (s + i)->sno; for(int j = i + 1; j < m + n; j++){ if(min > (s + j)->sno){ min_index = j; min = (s + j)->sno;//每次取最小值 } } STU temp; if(min_index != i){ temp = *(s + i); *(s + i) = *(s + min_index); *(s + min_index) = temp; } } for(int i = 0; i < m + n; i++){ printf("%d %d\n", (s + i)->sno, (s + i)->grade); } free(s); s = NULL; } return 0; }
0.0分
0 人评分