[TOJ 1215] Data Structure exercise questions-merge tables (vector merge), toj1215

Source: Internet
Author: User

[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 ;}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.