Код:
#include <fstream>#include <cmath>void first_task(std::ifstream &cin, std::ofstream &cout) { int n, k = 1; cin >> n >> k; cout << n / k;}void second_task(std::ifstream &cin, std::ofstream &cout) { int N; cin >> N; cout << 2 * (N / 2 + 1);}void third_task(std::ifstream &cin, std::ofstream &cout) { int N; cin >> N; auto t = [](int c, int N){return c / (int) pow(10, N) % 10;}; cout << t(N, 2) + t(N, 1) + t(N, 0);}void fourth_task(std::ifstream &cin, std::ofstream &cout) { int N; cin >> N; for (int it = 0; it < log2(N); ++it) { cout << pow(2, it) << " "; }}void fifth_task(std::ifstream &cin, std::ofstream &cout) { int h, a, b; cin >> h >> a >> b; int h0 = h - a, dx = a - b; int g = 1 + h0/dx + (h0%dx + dx - 1)/dx; if (g < 0) cout << INFINITY; else cout << g;}int main() { std::ifstream cin("input.txt"); std::ofstream cout("output.txt"); // Choose your function int N = 0; // 0-4 void (*tasks[5]) (std::ifstream &, std::ofstream &) = {first_task, second_task, third_task, fourth_task, fifth_task}; tasks[N](cin, cout); return 0;}РОПОР и ТОПОР
Объяснение:
Представим что имеем дело с 4-ичной системой счисления { 0 - О, 1 - П, 2 - Р, 3 - Т }. В таком случае вышенаписанный ряд можно представить в такой виде:
1. (00000) = 0 в 10ичной СС
2. П (00001) = 1 в 10ичной СС
3. Р (00002) = 2 в 10ичной СС
4. Т (00003) = 3 в 10ичной СС
5. ОООПО (00010) = 4 в 10ичной СС
...
Исходя из этого, чтобы получить слово, находящееся на 531 месте и 787 месте, достаточно перевести числа 530 и 786 в 4-ичную систему счисления и заменить цифры буквами.
1.
530 / 4 = 132 (2 остаток)
132 / 4 = 33 (0 остаток)
33 / 4 = 8 (1 остаток)
8 / 4 = 2 (0 остаток)
530(10) = 20102 (4)
Замена: РОПОР
2.
786 / 4 = 196 (2 остаток)
196 / 4 = 49 (0 остаток)
49 / 4 = 12 (1 остаток)
12 / 4 = 3 (0 остаток)
786(10) = 30102(4)
Замена: ТОПОР
var
count,i: integer;
A: array [1..30] of integer;
begin
for i:=1 to 30 do
begin
A[i]:= -100 + random(206);
writeln('A[',i,'] = ', A[i]);
end;
for i:=1 to 30 do
if(A[i] mod 2 = 0) then inc(count);
Writeln;Writeln;
Writeln('Кол-во четных элементов: ', count);
end.
2 ЗАДАЧА:
const
N = 30;
var
count,i: integer;
A: array [1..N] of integer;
begin
for i:=1 to N do
begin
A[i]:= -15 + random(22);
writeln('A[',i,'] = ', A[i]);
end;
for i:=1 to 30 do
if(A[i] mod 3 = 0) then A[i]:=-A[i];
Writeln;Writeln;
for i:=1 to N do
writeln('A[',i,'] = ', A[i]);
end.