题解 | #有序序列合并#
有序序列合并
https://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
#include <stdio.h> #include<stdlib.h> int compare1(const void* a, const void* b) { return (*(int*)a - *(int*)b); //升序 //return ( *(int*)b - *(int*)a );//降序 } int main() { int a, b; scanf("%d %d", &a, &b); int* p = (int*)malloc(sizeof(int) * (a + b)); for (int i = 0; i < (a + b); i++) { scanf("%d", &p[i]);//这里本来是想着可能需要把\n给吞掉的,但是聪明反被聪明误笑死 } qsort(p, a + b, sizeof(int), compare1);//排序 for (int i = 0; i < (a + b); i++) { printf("%d ", p[i]); } return 0; }