组合不重复数字

题意:

    有两个数组,数组中的元素都是不同的。分别从两个数组中挑一个数字, 然后相加,组合成新的数字,所有新组成数字也不能有相同的。

题目链接

 

思路:

   组成不同数字的题。

  先分别排序,然后依次对应相加。就肯定不会有一样的数字。

#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
int a[105], b[105];
int main()
{
	int T, i, n;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++)
			scanf("%d", &a[i]);
		for (i = 0; i < n; i++)
			scanf("%d", &b[i]);
		sort(a, a + n);
		sort(b, b + n);
		for (i = 0; i < n; i++)
			cout << a[i] << " ";
		cout << endl;
		for (i = 0; i < n; i++)
			cout << b[i] << " ";
		cout << endl;
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值