[TOJ 1215] Data Structure exercise questions-merge tables (vector merge), toj1215
Description
It is known that va and vb are non-decreasing ordered linear tables, respectively. va and vb are combined into a new linear table vc, And the vc is still not decreasing order.
In this question, the linear table element is an integer. The maximum length of a linear table is 1000.
Input
There are multiple groups of input data. The number of groups of the first behavior test data is t, followed by 2 t rows. Each group of test data has two rows:
The first number in the first row is the number n of elements in va, followed by n integers, representing all elements in va.
The first number of elements in the second row is m, followed by m integers, representing all elements of vb.
Output
Output the merged length and all vc elements.
Sample input
2
2 1 2
2 2 3
3 1 2 3
3 4 5 6
Sample output
4 1 2 3
6 1 2 3 4 5 6
# Include <vector> # include <iostream> # include <cstring> # include <algorithm> using namespace std; int main () {vector <int> v1, v2, v3; vector <int>: iterator it; int t, n, m, a, s; cin> t; while (t --) {s = 0; cin> n; s + = n; while (n --) {scanf ("% d", & a); v1.push _ back (a);} cin> m; s + = m; while (m --) {scanf ("% d", & a); v2.push _ back (a);} v3.insert (v3.end (), v1.begin (), v1.end ()); // v1 inserts v3 v3.insert (v3.end (), v2.begin (), v2.end (); // V2 insert v3 sort (v3.begin (), v3.end (); // vector sort cout <s; for (it = v3.begin (); it! = V3.end (); it ++) {cout <"<* it;} v1.clear (); v2.clear (); v3.clear (); cout <endl ;}}