Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <time.h>
- #include <iomanip>
- using namespace std;
- int main() {
- setlocale(LC_ALL, "rus");
- const int N = 10;
- int A[N] = { 1, 10, -2, 100, 50, 43, -32, 65, 16, 1 };
- int B[N];
- cout << "Выберите способ ввода элементов массива\r\n"
- "0 - Инициализация в коде\r\n"
- "1 - Заполнение случайными числами\r\n"
- "2 - Ввод с клавиатуры\r\n";
- int inp_method;
- cin >> inp_method;
- enum
- {
- fill_in_code,
- fill_rand,
- fill_keyboard,
- };
- switch (inp_method) {
- case fill_in_code:
- break;
- case fill_rand:
- srand(static_cast<int>(time(0)));
- for (int i = 0; i < N; i++)
- A[i] = rand() % 101 - rand() % 101;
- break;
- case fill_keyboard:
- for (int i = 0; i < N; i++)
- cin >> A[i];
- break;
- default:
- return 0;
- }
- cout << "Исходный массив:" << endl;
- for (int i = 0; i < N; i++) {
- cout << setw(5) << A[i];
- }
- cout << endl;
- for (int i = 0; i < N; i++) {
- int number = 0;
- for (int j = N - 1; j >= i; j--) {
- if (A[j] <= A[i]) number++;
- }
- B[i] = number;
- }
- cout << "Массив B:" << endl;
- for (int i = 0; i < N; i++) {
- cout << setw(5) << B[i];
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement