Advertisement
Caneq

lb3.1.8

Nov 9th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <time.h>  
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main() {
  8.     setlocale(LC_ALL, "rus");
  9.     const int N = 10;
  10.     int A[N] = { 1, 10, -2, 100, 50, 43, -32, 65, 16, 1 };
  11.     int B[N];
  12.     cout << "Выберите способ ввода элементов массива\r\n"
  13.         "0 - Инициализация в коде\r\n"
  14.         "1 - Заполнение случайными числами\r\n"
  15.         "2 - Ввод с клавиатуры\r\n";
  16.     int inp_method;
  17.     cin >> inp_method;
  18.     enum
  19.     {
  20.         fill_in_code,
  21.         fill_rand,
  22.         fill_keyboard,
  23.     };
  24.  
  25.     switch (inp_method) {
  26.     case fill_in_code:
  27.         break;
  28.     case fill_rand:
  29.         srand(static_cast<int>(time(0)));
  30.         for (int i = 0; i < N; i++)
  31.             A[i] = rand() % 101 - rand() % 101;
  32.         break;
  33.     case fill_keyboard:
  34.         for (int i = 0; i < N; i++)
  35.             cin >> A[i];
  36.         break;
  37.     default:
  38.         return 0;
  39.     }
  40.  
  41.     cout << "Исходный массив:" << endl;
  42.     for (int i = 0; i < N; i++) {
  43.         cout << setw(5) << A[i];
  44.     }
  45.     cout << endl;
  46.  
  47.  
  48.     for (int i = 0; i < N; i++) {
  49.         int number = 0;
  50.         for (int j = N - 1; j >= i; j--) {
  51.             if (A[j] <= A[i]) number++;
  52.         }
  53.         B[i] = number;
  54.     }
  55.  
  56.  
  57.     cout << "Массив B:" << endl;
  58.     for (int i = 0; i < N; i++) {
  59.         cout << setw(5) << B[i];
  60.     }
  61.     cout << endl;
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement