#include<iostream>
#include <vector>
#include<algorithm>
using namespace std;
void combineBySort(vector<int> &a,int sum1,vector<int> &b,int sum2)
{
vector<int> result;
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sum1 = a.size();
sum2 = b.size();
int i=0,j=0;
while(i != sum1 && j != sum2)
{
if(a[i]<b[j])
{
result.push_back(a[i]);
++i;
}
else
{
result.push_back(b[j]);
++j;
}
}
if(i != sum1)
{
while(i != sum1)
{
result.push_back(a[i]);
++i;
}
}
else
{
while(j != sum2)
{
result.push_back(b[j]);
++j;
}
}
vector<int>::iterator iend = unique(result.begin(),result.end());
vector<int>::iterator iter = result.begin();
for(;iter != iend;++iter)
{
cout<<*iter;
}
}
int main()
{
int sum1,sum2,i;
vector<int> a,b;
cin>>sum1;
for(i=0;i<sum1;i++)
{
int tempt;
cin>>tempt;
a.push_back(tempt);
}
cin>>sum2;
for(i=0;i<sum2;i++)
{
int tempt;
cin>>tempt;
b.push_back(tempt);
}
combineBySort(a,sum1,b,sum2);
return 0;
}
华为oj 整形数组合并
最新推荐文章于 2021-12-02 11:53:43 发布