Guest User

Untitled

a guest
Nov 21st, 2014
188
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<vector>
  3. int merge(int n1, std::vector <int> &vec1, int n2, std::vector <int> &vec2) {
  4.   std::vector<int> vec(n1+n2);
  5.   int a;
  6.   for (int k1 = 0; k1 < n1; k1++) {
  7.     vec[k1] = vec1[k1];
  8.   }
  9.   for (int k2 = 0; k2 < n2; k2++) {
  10.     vec[n1 + k2] = vec2[k2];
  11.   }
  12.   for (int i = 0; i < n1 + n2 - 2; i++) {
  13.     if (vec[i] > vec[i+1]) {
  14.       a = vec[i];
  15.       vec[i] = vec[i+1];
  16.       vec[i+1] = a;
  17.     }
  18.   }
  19.   return vec[n1+n2];
  20. }
  21.  
  22. int main() {
  23.   int n1;
  24.   int n2;
  25.   std::vector<int> vec1(n1);
  26.   std::vector<int> vec2(n2);
  27.   std::cin >> n1;
  28.   for (int i = 0; i < n1; i++) {
  29.     std::cin >> vec1[i];
  30.   }
  31.   std::cin >> n2;
  32.   for (int j = 0; j < n2; j++) {
  33.     std::cin >> vec2[j];
  34.   }
  35.   merge(n1, vec1, n2, vec2);
  36.   int Answer[n1+n2];
  37.   for (int q =0; q < n1 + n2; q++) {
  38.     int vec[n1 + n2];
  39.     Answer[q] = vec[q];
  40.     std::cout << Answer[q] << " ";
  41.   }
  42. }
RAW Paste Data