Ilitid

Билет 16

Dec 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. using namespace std;
  4.  
  5. int main(){
  6.     setlocale(LC_CTYPE, "rus");
  7.     int N=7, M=6, step, i=0, j=0;
  8.     int A[N] = {2, 7, 8, 11, 15, 20, 30}; // i
  9.     int B[M] = {1, 9, 16, 21, 25, 40}; // j
  10.     int C[M+N];
  11.  
  12.     for (step = M+N-1; step >= 0; step--){
  13.         if (((A[i] < B[j]) && (i < N)) || (j > M)){
  14.             C[step] = A[i];
  15.             i++;
  16.         }
  17.         else{
  18.             C[step] = B[j];
  19.             j++;
  20.         }
  21.     }
  22.  
  23.     for (i = 0; i < M+N; i++) cout<<C[i]<<" ";
  24.  
  25.     return 0;
  26. }
Add Comment
Please, Sign In to add comment