Код
#include <iostream>#include <vector>int main() { int n; std::vector<int> sequence; std::cin >> n; for(auto i = 0; i < n; ++i) { int number; std::cin >> number; sequence.push_back(number); } int as = 0, bs = 0, cs = 0; for (auto &el : sequence) { switch (el) { case 1: ++as; break; case 2: ++bs; break; case 3: ++cs; break; default: throw std::runtime_error("All elements shall be into [1;3] range."); } } int an_answer = std::min({bs + cs, as + cs, bs + cs}); std::cout << an_answer << std::endl; return 0;}
handsfree = true;
var
a: array[1..100] of real;
i, n, j, count: integer;
sum: real;
begin
{ввод массива}
if handsfree then
n := random(20) + 5
else begin
write('n = ');
readln(n);
end;
writeln('Данные массива:');
for i := 1 to n do
begin
if handsfree then begin
a[i] := (random(10) - 5) * 0.5;
write(a[i], ' ');
end
else readln(a[i]);
end;
writeln();
{подсчет суммы и кол-ва}
sum := 0;
count := 0;
for i := 1 to n do
begin
if a[i] < 0 then
sum := sum + a[i];
if a[i] = 0.5 then
count := count + 1;
end;
writeln('count = ', count);
writeln('sum = ', sum);
end.