题解 | #整型数组合并#
整型数组合并
https://www.nowcoder.com/practice/c4f11ea2c886429faf91decfaf6a310b
// HJ80 整型数组合并.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, n;
cin >> m;
vector<int>s1(m,0);
for (int i = 0; i < m; i++)
cin >> s1[i];
cin >> n;
vector<int>s2(n,0);
for (int i = 0; i < n; i++)
cin >> s2[i];
vector<int>str;
for (int i = 0; i < m; i++)
{
str.push_back(s1[i]);
}
for (int i = 0; i < n; i++)
{
str.push_back(s2[i]);
}
sort(str.begin(), str.end());
str.erase(unique(str.begin(), str.end()),str.end());//unique去除数组或容器中相邻重复项
for (int i = 0; i < str.size(); i++)//erase删除末尾重复项
{
cout << str[i];
}
return 0;
}



查看14道真题和解析