描述:
给你两个有序且升序的数组,请你把它们合成一个升序数组并输出
Give you two ordered ascending array, you put them into one ascending array and output.
输入:
第一行为一个正整数n,n<=20 ;
第二行为n个数字,这n个数字用空格隔开
第三行为一个正整数m,m<=20 ;
第四行为M个数字,这m个数字用空格隔开
The first line is a positive integer n, n <= 20;
The second line are n numbers separated by space
The third is a positive integer m, m <= 20;
The fourth line are m numbers separated by space
输出:
输出合并后的数组,每个数字占一行,
Output the combined array, each number per line,
输入样例:
3 1 3 7 5 2 4 6 8 10
输出样例:
1 2 3 4 6 7 8
10
#include<iostream> using namespace std; int main() { int n,m,i,j,temp; cin>>n; int c[100]; for(i=0;i<n;i++)//输入a[n] { cin>>c[i]; } cin>>m; for(i=n;i<m+n;i++)//输入b[m] { cin>>c[i]; } for(i=0;i<m+n;i++)//c[n+m]排序并输出 { for(j=i+1;j<m+n;j++) { if(c[i]>c[j]) { temp=c[i]; c[i]=c[j]; c[j]=temp; } } cout<<c[i]<<endl; } return (0); }