将两个已经按照升序排列的数组合并为一个数组,而且按照升序排列
我的代码是这样的:不知道错在哪里
#include<stdio.h>
int main(){
int a[100];
int i,j,temp;
for(i=0;i<100;i++){
scanf("%d ",&a[i]);
}
for(j=0;j<99;j++){
for(i=0;i<99-j;i++){
if(a[i]>a[i+1]){
temp=a[i];a[i]=a[i+1];a[i+1]=temp;
}
}
}
for(i=0;i<100;i++){
if(a[i]==9999) continue;
printf("%d ",a[i]);
}
return 0;
}
这是原题:
题目描述
Write a program that reads in two lists of ordered numbers (ascending order), and merge them into one ordered list.
输入格式
Two lists of integers in ascending order. Both lists are in the same line with 9999 as the sentinel for separating two lists. The elements in each list is separated by a space. Use EOF to end the input.
输出格式
Print out a list of integers in ascending order with each number separated by a space.
样例输入
将样例输入复制到剪贴板
11 42 50 662 732 9999 12 31 45 63 96 365 9999
样例输出
11 12 31 42 45 50 63 96 365 662 732