sofiyakoroleva3
08.06.2022 22:16

1. Найдите сумму следующих чисел в двоичной системе счисления: а) 13234 и 5127
б) 12406 и 41810
в) 7678 и 111223

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
kupmvik
17.03.2023 05:57
// PascalABC.NET 3.0, сборка 1128
const
  nmax=100;
var
  n,i,j,nn,nz,np,t:integer;
  a,an,az,ap:array[1..nmax] of integer;
begin
  // формируем массив и выводим его
  Write('Количество элементов в массиве: '); Read(n);
  for i:=1 to n do begin
    a[i]:=Random(11)-5;
    Write(a[i],' ')
    end;
  Writeln;
  // разбиваем массив на три подмассива
  nn:=0; nz:=0; np:=0;
  for i:=1 to n do
    if a[i]<0 then begin nn:=nn+1; an[nn]:=a[i] end
    else
      if a[i]=0 then begin nz:=nz+1; az[nz]:=a[i] end
      else begin np:=np+1; ap[np]:=a[i] end;
  // сортируем массив с отрицательными элементами по убыванию
  for i:=1 to nn-1 do
    for j:=1 to nn-1 do
      if an[j]<an[j+1] then
        begin t:=an[j]; an[j]:=an[j+1]; an[j+1]:=t end;
  // сортируем массив с положительными элементами по возрастанию
  for i:=1 to np-1 do
    for j:=1 to np-1 do
      if ap[j]>ap[j+1] then
        begin t:=ap[j]; ap[j]:=ap[j+1]; ap[j+1]:=t end;
  // формируем новое содержимое массива a
  i:=0;
  for j:=1 to nz do begin i:=i+1; a[i]:=az[j] end;
  for j:=1 to np do begin i:=i+1; a[i]:=ap[j] end;
  for j:=1 to nn do begin i:=i+1; a[i]:=an[j] end;
  // вывод результата
  for i:=1 to n do Write(a[i],' ');
  Writeln
end.

Тестовое решение:
Количество элементов в массиве: 15
1 2 5 0 -5 -3 0 0 1 -4 3 -2 -2 0 -5
0 0 0 0 1 1 2 3 5 -2 -2 -3 -4 -5 -5
0,0(0 оценок)
Ответ:
Marysilly
26.02.2021 14:53

С++20

#include <iostream>#include <vector>class Point {public:    int x, y;    Point() = default;    Point(const Point &) = default;    Point(int _x, int _y) : x(_x), y(_y) {}    Point operator + (const Point& p) const {        return Point {x + p.x, y + p.y};    }    Point operator - (const Point& p) const {        return Point {x - p.x, y - p.y};    }    std::vector<Point> operator & (const Point& p) const {        return std::vector<Point> {                Point {x + p.x, y + p.y},                Point {x - p.x, y + p.y},                Point {x + p.x, y - p.y},                Point {x - p.x, y - p.y},                Point {x + p.y, y + p.x},                Point {x - p.y, y + p.x},                Point {x + p.y, y - p.x},                Point {x - p.y, y - p.x},        };    }    static Point max (const Point& p1, const Point& p2) {        return Point {std::max(p1.x, p2.x), std::max(p1.y, p2.y)};    }    static Point min (const Point& p1, const Point& p2) {        return Point {std::min(p1.x, p2.x), std::min(p1.y, p2.y)};    }    [[nodiscard]] int distance_to_by_ch (const Point & p) const {        return std::max(std::abs(p.x - x), std::abs(p.y - y));    }    [[nodiscard]] int distance_to_by_m (const Point & p) const {        return std::abs(p.x - x) + std::abs(p.y - y);    }    friend std::ostream &operator << (std::ostream &os, Point const &p) {        return os << "(" << p.x << ";" << p.y << ")";    }    Point & operator = (const Point &) = default;    bool operator == (const Point & p) const {        return x == p.x && y == p.y;    }};class Horse {public:    const Point p;    explicit Horse (const Point position) : p(position) { }    [[nodiscard]] bool can_I_kill_this_guy (const Point & m) const {        auto field = p & Point{2, 3};        return std::find(field.begin(), field.end(), m) != field.end();    }};std::istream &to_number(std::istream &stream) {    char ch;    do {        ch = stream.get();    }    while (!isalpha(ch));    if (isupper(ch)) ch -= 16; else ch -= 48;    stream.putback(ch);    return stream;}int main () {    Point horse_p{}, stranger_p{};    std::cin >> horse_p.x >> to_number >> horse_p.y;    std::cin >> stranger_p.x >> to_number >> stranger_p.y;    Horse jack(horse_p);    std::cout << "I am a Horse placed on " << jack.p << ". "              << "Can I kill those guy on " << stranger_p << "? "              << "-> " << std::boolalpha << jack.can_I_kill_this_guy(stranger_p); }
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
Поле шахматной доски определяется парой – буква и цифра. Буква (a … h) означает горизонталь при счет
0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота