Ozon Tech Challenge 2020 (Div.1 + Div.2, Rated, T-shirts + prizes!) A. Kuroni and the Gifts(水题)

传送门

题意:

给两个长度为n的数组a,b
每个数组里的元素各不相同
问如何从两个数组中任选两个出来相加,得到的新数组里的元素都不相同

思路:

既然a,b两个数组里的元素都各不相同,那把它们从小到大排序,然后相加,得到的元素肯定都各不相同,排序输出即可

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
#define PII make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int MAXN=2e5+50;
const int inf=0x3f3f3f3f;
const int M=5000*4;
int n,m,k;
int a[150],b[150];
int main()
{   
    int t;
    cin>>t;
    while(t--){
    scanf("%d",&n);
    rep(i,1,n)cin>>a[i];
    rep(i,1,n)cin>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    rep(i,1,n){
        if(i!=n)cout<<a[i]<<" ";
        else cout<<a[i]<<endl;
    }
    rep(i,1,n){
        if(i!=n)cout<<b[i]<<" ";
        else cout<<b[i]<<endl;
    }
}
    return 0;
} 
发布了141 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_44091178/article/details/104647603