合并有序数组



合并有序数组(Merging sorted array)

时限:1000ms 内存限制:10000K 总时限:3000ms

描述:

给你两个有序且升序的数组,请你把它们合成一个升序数组并输出
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 i,m,n,c[40],j;
	cin>>m;
	for(i=0;i<m;i++)
	{
		cin>>c[i];   //输入前m个数
	}
	cin>>n;
	for(i=m;i<m+n;i++)
	{
		cin>>c[i];  //输入后n个数
	}
	for(i=0;i<m+n;i++)
	{
		for(j=i+1;j<m+n;j++)
		{
			
                      int temp;
		      if(c[i]>c[j])
		      {
			    temp=c[i];
			    c[i]=c[j];
			    c[j]=temp;
		      }     //将数组升序排列
		      else
		      continue;
	       }
        }
	for(i=0;i<m+n;i++)
	{
		cout<<c[i]<<endl;
	}
	
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值