NYOJ 839 合并

来源:互联网 发布:云计算市场规模 编辑:程序博客网 时间:2024/06/06 01:36

合并

时间限制:3000 ms  |  内存限制:65535 KB
难度:0
描述

现在给你两堆数,每个堆中n个数。你的任务是把这两个堆成一个堆,并把合并后的堆中的元素按从小到大的顺序输出。例如n=5时,一个堆是{1,2,3,4,5},第二个堆是{5,6,7,8,9}那么你就应该输出1 2 3 4 5 6 7 8 9。(一堆中可能有重复的数)

输入
第一行输入一个整数T(1≤T≤100),表示有T组测试数据。
每组数据先输入一个整数N(1≤N≤10),表示每个堆中元素的个数。然后输入N个整数A(0≤A<100),最后输入N个整数B(0≤B<100)。
输出
把合并后的堆中的元素按从小到大的顺序输出。
样例输入
251 2 3 4 55 6 7 8 9618 88 43 5 10 78 94 99 37 92 3 52 
样例输出
1 2 3 4 5 6 7 8 9 3 5 10 18 37 43 52 78 88 92 94 99 
来源

原创


#include <stdio.h>#include <iostream>#include <string.h>#include <math.h>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <bits/stdc++.h>using namespace std;int main(){    int t,n,text;    int a[110];    while(~scanf("%d",&t)){    while(t--){        scanf("%d",&n);        memset(a,-1,sizeof(a));        for(int i=0;i<2*n;i++){            scanf("%d",&text);            a[text]=text;        }        for(int i=0;i<110;i++){            if(a[i]>=0)            printf("%d ",a[i]);        }        printf("\n");    }    }    return 0;}


0 0
原创粉丝点击