import random
while True:
s = int(input('Введите строку: '))
d = int(input('Введите стобец: '))
if s in range(5):
if d in range(5):
break
print('Промежуток [0:4]')
array = []
for _ in range(5):
b = []
for _ in range(5):
b.append(random.randint(-10, 10))
print(f'{" ".join(str(num) for num in b)}')
array.append(b)
print('Задание 2:')
print(f'{" ".join(str(num) for num in array[s])}')
print('Задание 3:')
st = ''
for i in range(5):
st += str(array[i][d]) + ' '
print(st)
print('Задание 4:')
m_el = 0
p_el = 0
for i in range(5):
for j in range(5):
if array[i][j] < 0:
m_el += 1
if array[i][j] > 0:
p_el += 1
print('Положительных элементов: ', p_el)
print('Отрицательных элементов: ', m_el)
#define use_CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cstring>
using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
const int N = 81;
const int N2 = 81;
int numbers[N];
int count = 0;
int count2 = 0;
string words[N];
string kwords[N2];
char the_string[N], * p;
char* next_token = nullptr;
int i = 0;
for (int k = 0; k < N; k++) {
numbers[k] = 0;
}
cout << "Введите строку:";
cin.getline(the_string, N); // начало ввода первого массива
p = strtok_s(the_string, " ", &next_token);
while (p != nullptr) {
words[i] = p;
i++;
p = strtok_s(nullptr, " ", &next_token);
count++;
} // конец ввода первого массива
cout << endl;
char the_string2[N2], * p2;
char* next_token2 = nullptr;
cout << "Введите нужные слова:";
cin.getline(the_string2, N2);
int j = 0;
p2 = strtok_s(the_string2, " ", &next_token2);
while (p2 != nullptr) {
kwords[j] = p2;
j++;
p2 = strtok_s(nullptr, " ", &next_token2);
count2++;
}
cout << endl;
for (int i = 0; i < count; i++) {
for (int j = 0; j < count2; j++) {
if (words[i] == kwords[j]) {
numbers[j] = numbers[j] + 1;
break;
}
}
}
int t; string d;
for (int j = 0; j < count2; j++) {
for (int i = 0; i < count2; i++) {
if (numbers[i] < numbers[i + 1]) {
t = numbers[i + 1];
numbers[i+1] = numbers[i];
numbers[i] = t;
d = kwords[i + 1];
kwords[i + 1] = kwords[i];
kwords[i] = d;
}
}
}
cout << endl;
for (int i = 0; i < count2; i++) {
cout << kwords[i] << " ";
}
return 0;
}