Problems in combinatorics. Solution examples

    Write a program that compares two integers entered from the keyboard. The program must indicate which number is greater, or, if the numbers are equal, display an appropriate message.

    Type two integers and press Enter.
    -> 34 67
    34 less than 67

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure main is A, B: Integer; begin Put_Line("Enter two integers on one line and press Enter."); put("-> "); Get(A); Get(B); --Enter 2 numbers if A > B then Put(Item =>; A, Width =>; 1); put("greater than"); Put(Item => B, Width => 1); elsif A< B then Put(Item =>A, Width => 1); put("less than"); Put(Item => B, Width => 1); else Put("Entered numbers are equal!"); end if; end main;

    Three integers are given. Find the largest of them (the program should output exactly one integer). The largest in this problem is understood as a number that is not less than any other.


  • -> 1 2 3
    Maximum of three numbers: 3
  • with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure main is A, B, C: Integer; max: Integer; begin Put_Line( "Enter three integers on one line and press Enter.") ; Put("-> "); Get(A); Get(B) ; Get(C); --Enter three integers max:=A; --default we consider that the number A is the maximum if B > max then --If B is greater than the maximum, then max:=B; --maximum number is B end if ; if C > max then --If C is greater than the maximum, then max:=C; --maximum number is C end if ; Put( "Maximum of three numbers:"& Integer"image(max) ); end main;

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure main is A, B, C: Integer; max: Integer; begin Put_Line("Enter three integers on one line and press Enter."); put("-> "); Get(A); Get(B); Get(C); --Enter three integers max:= A; --by default, we assume that the number A is the maximum if B > max then --If B is greater than the maximum, then max:= B; --maximum number is B end if; if C > max then --If C is greater than max, then max:= C; --maximum number is equal to C end if; Put("Maximum of three numbers:" & Integer"image(max)); end main;

    Given three natural numbers A, B, C. Determine if a triangle exists with these sides. If the triangle exists, print a message that a triangle with such sides exists, otherwise print that the triangle does not exist.

  • Type in the three sides of the triangle and press Enter.
    -> 3 4 5
    A triangle with sides 3, 4, 5 exists.
  • A triangle is three points that do not lie on the same line. A triangle exists only when the sum of any two of its sides is greater than the third.

  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; --For reading integers with Ada.Text_IO ; use Ada.Text_IO ; --To display strings procedure main is a, b, c: Integer; begin Put_Line( "Enter three sides of a triangle and press Enter.Enter.") ; Put("-> "); Get(a); Get(b) ; Get(c); --Read the sides of the triangle if a + b > c and then b + c > a and then c + a > b then --Check all conditions in one line Put( "Triangle with Sides"& Integer"image(a) & "," & Integer"image(b) & "," & Integer"image(c) & " exists" ) ; else Put( "Triangle with Sides"& Integer"image(a) & "," & Integer"image(b) & "," & Integer"image(c) & " does not exist" ) ; end if ; end main;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; --To read integers with Ada.Text_IO; use Ada.Text_IO; --To print strings procedure main is a, b, c: Integer; begin Put_Line("Enter the three sides of the triangle and press Enter.Enter."); put("-> "); get(a); get(b); get(c); --Read triangle sides if a + b > c and then b + c > a and then c + a > b then --Check all conditions in one line Put("Triangle with sides" & Integer"image(a) & " ," & Integer"image(b) & "," & Integer"image(c) & " exists"); else Put("Triangle with sides" & Integer"image(a) & "," & Integer"image( b) & "," & Integer"image(c) & " does not exist"); end if; end main;

    Three integers are given. Determine how many of them match. The program should output one of the numbers: 3 (if all are the same), 2 (if two are the same), or 0 (if all are different).

  • Type three integers and press Enter.
    -> 1 2 3
    0
  • with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure Main is A, B, C: Integer; begin Put_Line( "Enter three integers and press Enter.") ; Put("-> "); Get(A); Get(B) ; Get(C); if A = B and then A = C then --If all three numbers match Put(Item => 3 , Width => 1 ) ; elsif A = B or A = C or B = C then --If two numbers match Put(Item => 2 , Width => 1 ) ; else --If same numbers No Put(Item => 0 , Width => 1 ) ; end if ; endMain;

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Main is A, B, C: Integer; begin Put_Line("Enter three integers and press Enter."); put("-> "); Get(A); Get(B); Get(C); if A = B and then A = C then --If all three numbers match Put(Item => 3, Width => 1); elsif A = B or A = C or B = C then --If two numbers match Put(Item => 2, Width => 1); else --If there are no identical numbers Put(Item => 0, Width => 1); end if; endMain;

    The chess rook moves horizontally or vertically. Given two different squares on a chessboard, determine if the rook can get from the first square to the second in one move. The program receives as input four numbers from 1 to 8 each, specifying the column number and row number, first for the first cell, then for the second cell. The program should print "YES" if it is possible to get to the second from the first cell by the move of the rook, or "NO" otherwise.


  • 4 4
    5 5
    NO
  • ) ; Put() ; Get(A); Get(B) ; Put() ; Get(C); Get(D); if A = C or B = D then Put("YES" ) ; else Put("NO" ) ; end if ; endMain;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure Main is subtype checkBoard is Integer range 1..8; A, B, C, D: checkBoard; begin Put_Line("Enter the column and row numbers for the two cells:"); Put("Enter the column and row numbers for the first cell and press: "); Get(A); Get(B); Put("Enter the column and row numbers for the second cell and press: "); Get(C); Get(D); if A = C or B = D then Put("YES"); else Put("NO"); end if; endMain;

    The chess king moves horizontally, vertically and diagonally, but only 1 square. Given two different cells on a chessboard, determine if the king can get from the first cell to the second in one move. The program receives as input four numbers from 1 to 8 each, specifying the column number and row number, first for the first cell, then for the second cell. The program should print "YES" if it is possible to get to the second from the first cell by the move of the king, or "NO" otherwise.

  • Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 4 4
    Enter the column and row numbers for the second cell and press: 5 5
    YES
  • "Enter the column and row numbers for the two cells:") ; Put( "Enter the column and row numbers for the first cell and press: ") ; Get(A); Get(B) ; Put( "Enter the column and row numbers for the second cell and press: ") ; Get(C); Get(D); if abs (A - C)<= 1 and then abs (B - D) <= 1 then -- the abs() command returns the absolute -- value (modulus) of number Put("YES"); else Put("NO" ) ; end if ; end main;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure main is subtype checkBoard is Integer range 1..8; A, B, C, D: checkBoard; begin Put_Line("Enter the column and row numbers for the two cells:"); Put("Enter the column and row numbers for the first cell and press: "); Get(A); Get(B); Put("Enter the column and row numbers for the second cell and press: "); Get(C); Get(D); if abs(A - C)<= 1 and then abs(B - D) <= 1 then -- команда abs() возвращает абсолютное --значение (модуль) числа Put("ДА"); else Put("НЕТ"); end if; end main;

    The chess bishop moves diagonally. Given two different cells of a chessboard, determine if the bishop can get from the first cell to the second in one move. The program receives as input four numbers from 1 to 8 each, specifying the column number and row number, first for the first cell, then for the second cell. The program should output "YES" if it is possible to get to the second from the first cell by the bishop's move, or "No" otherwise.

  • Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 4 4
    Enter the column and row numbers for the second cell and press: 5 5
    YES
  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure main is subtype checkBoard is Integer range 1 ..8 ; A, B, C, D: checkBoard; begin Put_Line( "Enter the column and row numbers for the two cells:") ; Put( "Enter the column and row numbers for the first cell and press: ") ; Get(A); Get(B) ; Put( "Enter the column and row numbers for the second cell and press: ") ; Get(C); Get(D); if abs (a - c) = abs (b - d) then Put("YES" ) ; else Put("NO" ) ; end if ; end main;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure main is subtype checkBoard is Integer range 1..8; A, B, C, D: checkBoard; begin Put_Line("Enter the column and row numbers for the two cells:"); Put("Enter the column and row numbers for the first cell and press: "); Get(A); Get(B); Put("Enter the column and row numbers for the second cell and press: "); Get(C); Get(D); if abs(a - c) = abs(b - d) then Put("YES"); else Put("NO"); end if; end main;

    The chess queen moves diagonally, horizontally or vertically. Given two different cells of a chessboard, determine if the queen can get from the first cell to the second in one move.

    Input data format:
    The program receives as input four numbers from 1 to 8 each, specifying the column number and row number, first for the first cell, then for the second cell.
    Output format:
    The program should output YES if it is possible to get from the first cell to the second by the queen's move, or NO otherwise.

    Example 1:
    Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 1 1
    Enter the column and row numbers for the second cell and press: 2 2
    YES

    Example 2:
    Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 1 1
    Enter the column and row numbers for the second cell and press: 2 3
    NO

  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure Main is subtype checkBoard is Integer range 1 ..8 ; A, B, C, D: checkBoard; begin Put_Line( "Enter the column and row numbers for the two cells:") ; Put( "Enter the column and row numbers for the first cell and press: ") ; Get(A); Get(B) ; Put( "Enter the column and row numbers for the second cell and press: ") ; Get(C); Get(D); if abs (A - C) = abs (B - D) or A = D or B = C then Put("YES" ) ; else Put("NO" ) ; end if ; endMain;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure Main is subtype checkBoard is Integer range 1..8; A, B, C, D: checkBoard; begin Put_Line("Enter the column and row numbers for the two cells:"); Put("Enter the column and row numbers for the first cell and press: "); Get(A); Get(B); Put("Enter the column and row numbers for the second cell and press: "); Get(C); Get(D); if abs(A - C) = abs(B - D) or A = D or B = C then Put("YES"); else Put("NO"); end if; endMain;

    The chess horse moves in the letter “G” - two squares vertically in any direction and one square horizontally, or vice versa. Given two different cells of a chessboard, determine if the knight can get from the first cell to the second in one move. The program receives as input four numbers from 1 to 8 each, specifying the column number and row number, first for the first cell, then for the second cell. The program should output YES if the knight can move from the first cell to the second one, or NO otherwise.

    Example 1:
    Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 1 1
    Enter the column and row numbers for the second cell and press: 1 4
    NO

    Example 2:
    Enter the column and row numbers for the two cells:
    Enter the column and row numbers for the first cell and press: 1 1
    Enter the column and row numbers for the second cell and press: 8 8
    NO

  • with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure main is subtype checkBoard is Integer range 1 ..8 ; A, B, C, D: Integer; begin Put_Line( "Enter the column and row numbers for the two cells:") ; Put( "Enter the column and row numbers for the first cell and press: ") ; Get(A); Get(B) ; Put( "Enter the column and row numbers for the second cell and press: ") ; Get(C); Get(D); if abs (A - C) = 2 and then abs (B - D) = 1 then Put("YES" ) ; elsif abs (A - C) = 1 and then abs (B - D) = 2 then Put("YES" ) ; else Put("NO" ) ; end if ; end main;

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure main is subtype checkBoard is Integer range 1..8; A, B, C, D: Integer; begin Put_Line("Enter the column and row numbers for the two cells:"); Put("Enter the column and row numbers for the first cell and press: "); Get(A); Get(B); Put("Enter the column and row numbers for the second cell and press: "); Get(C); Get(D); if abs(A - C) = 2 and then abs(B - D) = 1 then Put("YES"); elsif abs(A - C) = 1 and then abs(B - D) = 2 then Put("YES"); else Put("NO"); end if; end main;

    The chocolate has the form of a rectangle divided into N×M slices. Chocolate can be broken once in a straight line into two parts. Determine if exactly K slices can be broken off from a chocolate bar in this way. The program receives three numbers as input: N, M, K. The program must output one of two words: "YES" or "No".

    Example 1:
    4
    2
    6
    YES

    Example 2:
    Number of slices horizontally: 2
    Number of slices vertically: 10
    How many slices to separate: 7
    NO

  • with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure Main is N, M, K: Integer; begin Put( "Number of slices horizontally:") ; Get(N) ; Put( "Number of slices vertically:") ; Get(M) ; Put( "How many slices to separate:") ; Get(K) ; if K > M * N then --If a chocolate bar is asked to break off more than the chocolate bar itself put("NO"); elsif K rem N = 0 and then K >= N then - Break off horizontally Put("YES"); elsif K rem M = 0 and then K >= M then - Break off vertically Put("YES"); else Put("NO" ) ; end if ; endMain;

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Main is N, M, K: Integer; begin Put("Number of slices horizontally: "); Get(N); Put("Number of slices vertically: "); Get(M); Put("How many slices to separate: "); Get(K); if K > M * N then --If the chocolate bar is asked to break off more than the chocolate bar itself Put("NO"); elsif K rem N = 0 and then K >= N then -- Break off horizontally Put("YES"); elsif K rem M = 0 and then K >= M then -- Break off vertically Put("YES"); else Put("NO"); end if; endMain;

    Yasha swam in a pool measuring N × M meters and got tired. At this point, he found himself X meters from one of the long ledges (not necessarily the nearest one) and Y meters from one of the short ledges. What is the minimum distance Yasha must swim to get out of the pool onto the side? The program receives the numbers N, M, X, Y as input. The program should output the number of meters that Yasha needs to swim to the side.

  • Pool Width: 23
    Pool length: 52
    Distance from Yasha to the long side: 8
    Distance from Yasha to a short side: 43
    You need to swim at least to get out of the pool: 8
  • It is possible that to solve the problem you will need to swap 2 variables. This algorithm looks something like this:

    a, b, tmp: Integer; -- Declaring variables. Two main and one auxiliary a:= 3; --Initialization of variable a b:= 5; --Initialization of variable b --Algorithm itself: tmp:= a; --Now tmp = 3 and a = 3 a:= b; --Now a = 5 and b = 5; b:=tmp; --Now b = 3

  • with Ada.Text_IO ; use Ada.Text_IO ; with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; procedure Main is N, M, X, Y: Integer; -- N - short edge, M - long edge: -- X - Distance to one of the long sides -- Y - Distance to one of the short sides Tmp: Integer; begin Put( "Pool Width: ") ; Get(N) ; Put( "Pool Length: ") ; Get(M) ; Put( "Distance from Yasha to a long side:") ; Get(X) ; Put( "Distance from Yasha to the short side:") ; Get(Y) ; if N > M then --If the sides are mixed up during input, then we change their places: Tmp:=M; --Save the length M to a temporary variable M:=N; --Assign the variable M a new value N:=Tmp; --Restore the length M in variable N end if ; Tmp:=X; --Assume the minimum distance is X if abs(N-X)< X then --If the distance to the second long edge is less than X, then Tmp:= N - X; --minimum distance is equal to the distance to the second long edge end if ; if Y< Tmp then --If the distance to the short edge is less than that found above -- minimum, then Tmp:=Y; --Minimum distance is Y end if ; if abs (M - Y)< Tmp then --If you swim closer to the second short side, then Tmp:= abs (M - Y) ; --minimum distance is equal to the distance to the second short ledge end if ; Put( "You need to swim at least to get out of the pool: ") ; Put(Item => Tmp, Width => 1 ) ; endMain;

    with Ada.Text_IO; use Ada.Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure Main is N, M, X, Y: Integer; -- N - short ledge, M - long ledge: -- X - Distance to one of the long ledges -- Y - Distance to one of the short ledges Tmp: Integer; begin Put("Pool Width: "); Get(N); Put("Pool length: "); Get(M); Put("Distance from Yasha to the long side: "); Get(X); Put("Distance from Yasha to the short edge: "); Get(Y); if N > M then --If the edges are mixed up during input, then we change their places: Tmp:= M; --Save the length M into a temporary variable M:= N; --Assign a new value to the variable M N:= Tmp; --Restore the length M in the variable N end if; Tmp:=X; --Assume the minimum distance is X if abs(N - X)< X then --Если до второго длинного бортика расстояние меньше X, то Tmp:= N - X; --минимальное расстояние равно расстоянию до второго длинного бортика end if; if Y < Tmp then --Если до короткого бортика расстояние меньше найденного выше --минимального, то Tmp:= Y; --Минимальное расстояние равно Y end if; if abs(M - Y) < Tmp then --Если до второго короткого бортика плыть ближе, то Tmp:= abs(M - Y); --минимальное расстояние равно расстоянию до второго короткого бортика end if; Put("Нужно проплыть минимум, чтобы выбраться из бассейна: "); Put(Item =>Tmp, Width => 1); endMain;

    The electronic clock shows the time in the h:mm:ss format (from 0:00:00 to 23:59:59), that is, first the number of hours is recorded, then the two-digit number of minutes is mandatory, then the two-digit number of seconds is mandatory. The number of minutes and seconds, if necessary, are padded to a two-digit number with zeros. N seconds have passed since the beginning of the day. Output what the clock shows. The input is a natural number N, not exceeding 10 7 (10000000). Output the answer to the problem.

    Input example 1:
    3602
    Output example 1:
    1:00:02

    Input example 2:
    129700
    Output example 2:
    12:01:40

  • with Ada.Long_Integer_Text_IO ; use Ada.Long_Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure Main is subtype Sub_LI is Long_Integer range 1 ..10000000 ; N: Sub_LI; h, m, s: Long_Integer; begin Get(N) ; h:= N / 3600 ; - We get the clock. The remainder of the division is discarded N:= N - h * 3600 ; --Get remaining seconds (minus hours) if h > 24 then --Since the clock cannot show > 24, we put everything in a readable form h:= h rem 24 ; --Remainder of dividing by 24 will give the exact number of hours elsif h = 24 then h:= 0 ; end if ; m:= N / 60 ; --Get minutes s:= N rem 60 ; --Get seconds Put(Item => h, Width => 1 ) ; Put(":"); --Output hours and ":" if m< 10 then --If the number of minutes is less than 10, output a leading 0 Put(Item => 0 , Width => 1 ) ; end if ; Put(Item => m, Width => 1 ) ; Put(":"); --Output minutes and ":" if s< 10 then --If the number of seconds is less than 10, output a leading 0 Put(Item => 0 , Width => 1 ) ; end if ; Put(Item => s, Width => 1 ) ; --Output seconds end Main;

    with Ada.Long_Integer_Text_IO; use Ada.Long_Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure Main is subtype Sub_LI is Long_Integer range 1..10000000; N: Sub_LI; h, m, s: Long_Integer; begin Get(N); h:= N / 3600; - We get the clock. The remainder of the division is discarded N:= N - h * 3600; --Get remaining seconds (minus hours) if h > 24 then --Since clocks can't read > 24, put everything in human-readable form h:= h rem 24; --The remainder of dividing by 24 will give the exact number of hours elsif h = 24 then h:= 0; end if; m:= N / 60; --Get minutes s:= N rem 60; --Get seconds Put(Item => h, Width => 1); Put(":"); --Output hours and ":" if m< 10 then --Если количество минут меньше 10, выводим ведущий 0 Put(Item =>0, Width => 1); end if; Put(Item => m, Width => 1); Put(":"); --Output minutes and ":" if s< 10 then --Если количество секунд меньше 10, выводим ведущий 0 Put(Item =>0, Width => 1); end if; Put(Item => s, Width => 1); --Output seconds end Main;

  • Three numbers are given. Arrange them in ascending order.
  • Input example:
    1 2 1
    Sample output:
    1 1 2
  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure Main is A, B, C: Integer; min, mid, max: Integer; begin Get(A) ; Get(B) ; Get(C); --Are looking for minimum value min:=A; if B< min then min:= B; end if ; if C < min then min:= C; end if ; --Looking for the maximum value max:=A; if B > max then max:= B; end if ; if C > max then max:= C; end if ; --Looking for the average value mid:=A; if B > min and B< max then mid:= B; end if ; if C >min and C< max then mid:= C; end if ; Put(Item =>min, Width => 1 ) ; put(" "); Put(Item => mid, width => 1 ) ; put(" "); Put(Item => max, Width => 1 ) ; endMain;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure Main is A, B, C: Integer; min, mid, max: Integer; begin Get(A); Get(B); Get(C); --Looking for the minimum value min:= A; if B< min then min:= B; end if; if C < min then min:= C; end if; --Ищем максимальное значение max:= A; if B >max then max:= B; end if; if C > max then max:= C; end if; --Looking for the average value mid:= A; if B > min and B< max then mid:= B; end if; if C >min and C< max then mid:= C; end if; Put(Item =>min, Width => 1); put(" "); Put(Item => mid, width => 1); put(" "); Put(Item => max, Width => 1); endMain;

    There are two boxes, the first is A1×B1×C1, the second is A2×B2×C2. Determine if one of these boxes can be placed inside the other, provided that the boxes can only be rotated 90 degrees around the edges. The program receives numbers A1, B1, C1, A2, B2, C2 as input. The program should output one of the following lines:
    - "Boxes are equal" if the boxes are the same,
    - "The first box is less than the second" if the first box can be placed in the second,
    - "First box more than a second" if the second box can be placed inside the first one.

    Example 1:
    First box dimensions: 1 2 3
    Second box dimensions: 3 2 1
    Boxes are equal

    Example 2:
    First box dimensions: 2 2 3
    Second box dimensions: 3 2 1
    The first box is larger than the second

  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure main is A1, B1, C1, A2, B2, C2: Integer; min, max, mid, tmp: Integer; begin Get(A1) ; Get(B1) ; Get(C1) ; Get(A2) ; Get(B2) ; Get(C2) ; --Bring the faces in line with the lengths A1 => A2, B1 => B2, C1 => C2: --A1 and A2 are the longest, C1 and C2 are the shortest -- "Spin" the first box: min:=A1; mid:=B1; max:=C1; if B1< min then mid:= min; min:= B1; end if ; if C1 < min then max:= min; min:= C1; end if ; if mid >max then tmp:= mid; mid:=max; max:=tmp; end if ; A1:=min; B1:=mid; C1:=max; -- "Spin" the second box: min:=A2; mid:=B2; max:=C2; if B2< min then mid:= min; min:= B2; end if ; if C2 < min then max:= min; min:= C2; end if ; if mid >max then tmp:= mid; mid:=max; max:=tmp; end if ; A2:=min; B2:=mid; C2:=max; --Checking the correspondence of boxes and displaying the result: if A1 = A2 and then B1 = B2 and then C1 = C2 then Put_Line("The boxes are equal" ) ; elsif A1 >= A2 and then B1 >= B2 and then C1 >= C2 then Put_Line( "The first box is larger than the second") ; Elsif A1<= A2 and then B1 <= B2 and then C1 <= C2 then Put_Line("The first box is smaller than the second") ; end if ; end main;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure main is A1, B1, C1, A2, B2, C2: Integer; min, max, mid, tmp: Integer; begin Get(A1); Get(B1); Get(C1); Get(A2); Get(B2); Get(C2); --Bring the sides in line with the lengths A1 => A2, B1 => B2, C1 => C2: --A1 and A2 - the longest, C1 and C2 - the shortest -- "Twist" the first box: min:= A1 ; mid:=B1; max:=C1; if B1< min then mid:= min; min:= B1; end if; if C1 < min then max:= min; min:= C1; end if; if mid >max then tmp:= mid; mid:=max; max:=tmp; end if; A1:=min; B1:=mid; C1:=max; -- "Spin" the second box: min:= A2; mid:=B2; max:=C2; if B2< min then mid:= min; min:= B2; end if; if C2 < min then max:= min; min:= C2; end if; if mid >max then tmp:= mid; mid:=max; max:=tmp; end if; A2:=min; B2:=mid; C2:=max; --Check if the boxes match and output the result: if A1 = A2 and then B1 = B2 and then C1 = C2 then Put_Line("Boxes are equal"); elsif A1 >= A2 and then B1 >= B2 and then C1 >= C2 then Put_Line("First box is bigger than second"); Elsif A1<= A2 and then B1 <= B2 and then C1 <= C2 then Put_Line("Первая коробка меньше второй"); end if; end main;

    Write a program that calculates the cost of a long-distance telephone conversation (the price of one minute is determined by the distance to the city where the subscriber is located). The initial data for the program are the area code and the duration of the call. Below are the codes of some cities and the recommended screen view while the program is running:

  • Calculate the cost of a telephone conversation.
    Enter initial data:
    City code -> 423
    Duration (integer minutes) -> 3
    Vladivostok city
    Price per minute: 4 rubles.
    Call cost: 12 rubles.
  • with Ada.Integer_Text_IO ; use Ada.Integer_Text_IO ; with Ada.Text_IO ; use Ada.Text_IO ; procedure Main is Code, Len: Integer; begin Put_Line ("Calculation of the cost of a telephone conversation.") ; Put_Line ("Enter initial data:") ; Put ("City code -> ") ; Get ( Code ) ; Put ("Duration (integer minutes) -> ") ; Get ( len ) ; case Code is when 423 => Put_Line ("Vladivostok city") ; Put_Line ("Price of a minute: 4 rubles.") ; Put ("Call cost: ") ; Put ( Item => len * 4 , Width=> 1 ) ; Put_Line (" rub.") ; when 095 => Put_Line ("Moscow city") ; Put_Line ("Price of a minute: 2 rubles.") ; Put ("Call cost: ") ; Put ( Item => len * 2 , Width=> 1 ) ; Put_Line (" rub.") ; when 815 => Put_Line ("City: Murmansk") ; Put_Line ("Price of a minute: 3 rubles.") ; Put ("Call cost: ") ; Put ( Item => len * 3 , Width=> 1 ) ; Put_Line (" rub.") ; when 846 => Put_Line ("Samara city") ; Put_Line ("Price of a minute: 1 rub.") ; Put ("Call cost: ") ; Put ( Item => len, Width => 1 ) ; Put_Line (" rub.") ; when others=> Put ("There is no city with this code in the database! Try again.") ; end case; end main;

    with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; with Ada.Text_IO; use Ada.Text_IO; procedure Main is Code, Len: Integer; begin Put_Line("Calculating the cost of a phone call."); Put_Line("Enter initial data:"); Put("City code -> "); get(Code); Put("Duration (integer minutes) -> "); get(len); case Code is when 423 => Put_Line("City: Vladivostok"); Put_Line("Price per minute: 4 rubles."); Put("Call cost: "); Put(Item => len * 4, Width => 1); Put_Line(" rub."); when 095 => Put_Line("City: Moscow"); Put_Line("Price per minute: 2 rubles."); Put("Call cost: "); Put(Item => len * 2, Width => 1); Put_Line(" rub."); when 815 => Put_Line("City: Murmansk"); Put_Line("Price per minute: 3 rubles."); Put("Call cost: "); Put(Item => len * 3, Width => 1); Put_Line(" rub."); when 846 => Put_Line("City: Samara"); Put_Line("Price per minute: 1 rub."); Put("Call cost: "); Put(Item => len, Width => 1); Put_Line(" rub."); when others => Put("There is no city with this code in the database! Try again."); end case; endMain;

The section briefly describes the operators if And case, function abs() and an algorithm for swapping variables.

Job type: 8
Theme: Prism

Condition

In a regular triangular prism ABCA_1B_1C_1, the sides of the base are 4, and side ribs are equal to 10 . Find the sectional area of ​​the prism by the plane passing through the midpoints of edges AB, AC, A_1B_1 and A_1C_1.

Show Solution

Solution

Consider the following figure.

Segment MN is the midline of triangle A_1B_1C_1, so MN = \frac12 B_1C_1=2. Likewise, KL=\frac12BC=2. In addition, MK = NL = 10. This implies that the quadrilateral MNLK is a parallelogram. Since MK\parallel AA_1, then MK\perp ABC and MK\perp KL. Therefore, quadrilateral MNLK is a rectangle. S_(MNLK) = MK\cdot KL= 10\cdot 2 = 20.

Answer

Job type: 8
Theme: Prism

Condition

The volume of a regular quadrangular prism ABCDA_1B_1C_1D_1 is 24 . Point K is the middle of edge CC_1 . Find the volume of the pyramid KBCD.

Show Solution

Solution

According to the condition, KC is the height of the pyramid KBCD . CC_1 is the height of the prism ABCDA_1B_1C_1D_1 .

Since K is the midpoint of CC_1 , then KC=\frac12CC_1. Let CC_1=H , then KC=\frac12H. Note also that S_(BCD)=\frac12S_(ABCD). Then, V_(KBCD)= \frac13S_(BCD)\cdot\frac(H)(2)= \frac13\cdot\frac12S_(ABCD)\cdot\frac(H)(2)= \frac(1)(12)\cdot S_(ABCD)\cdot H= \frac(1)(12)V_(ABCDA_1B_1C_1D_1). Consequently, V_(KBCD)=\frac(1)(12)\cdot24=2.

Answer

Source: "Mathematics. Preparation for the exam-2017. Profile level". Ed. F. F. Lysenko, S. Yu. Kulabukhova.

Job type: 8
Theme: Prism

Condition

Find the lateral surface area of ​​a regular hexagonal prism whose base side is 6 and its height is 8.

Show Solution

Solution

The area of ​​the lateral surface of the prism is found by the formula S side. = P main. · h = 6a\cdot h, where P main. and h are, respectively, the perimeter of the base and the height of the prism, equal to 8 , and a is the side of a regular hexagon, equal to 6 . Therefore, S side. = 6\cdot 6\cdot 8 = 288.

Answer

Source: "Mathematics. Preparation for the exam-2017. profile level. Ed. F. F. Lysenko, S. Yu. Kulabukhova.

Job type: 8
Theme: Prism

Condition

In a vessel that has the correct shape triangular prism poured water. The water level reaches 40 cm. At what height will the water level be if it is poured into another vessel of the same shape, whose base side is twice that of the first? Express your answer in centimeters.

Show Solution

Solution

Let a be the side of the base of the first vessel, then 2 a is the side of the base of the second vessel. By condition, the volume of liquid V in the first and second vessel is the same. Denote by H the level to which the liquid has risen in the second vessel. Then V= \frac12\cdot a^2\cdot\sin60^(\circ)\cdot40= \frac(a^2\sqrt3)(4)\cdot40, And, V=\frac((2a)^2\sqrt3)(4)\cdot H. From here \frac(a^2\sqrt3)(4)\cdot40=\frac((2a)^2\sqrt3)(4)\cdot H, 40=4H, H=10.

Answer

Source: "Mathematics. Preparation for the exam-2017. profile level. Ed. F. F. Lysenko, S. Yu. Kulabukhova.

Job type: 8
Theme: Prism

Condition

In a regular hexagonal prism ABCDEFA_1B_1C_1D_1E_1F_1 all edges are 2 . Find the distance between points A and E_1 .

Show Solution

Solution

Triangle AEE_1 is right-angled, since edge EE_1 is perpendicular to the plane of the base of the prism, angle AEE_1 will be a right angle.

Then by the Pythagorean theorem AE_1^2 = AE^2 + EE_1^2. Find AE from the triangle AFE using the cosine theorem. Each interior angle of a regular hexagon is 120^(\circ). Then AE^2= AF^2+FE^2-2\cdot AF\cdot FE\cdot\cos120^(\circ)= 2^2+2^2-2\cdot2\cdot2\cdot\left (-\frac12 \right).

Hence, AE^2=4+4+4=12,

AE_1^2=12+4=16,

AE_1=4.

Answer

Source: "Mathematics. Preparation for the exam-2017. profile level. Ed. F. F. Lysenko, S. Yu. Kulabukhova.

Job type: 8
Theme: Prism

Condition

Find the area of ​​the lateral surface of a straight prism whose base is a rhombus with diagonals equal to 4\sqrt5 and 8 , and a side edge equal to 5 .

Show Solution

Solution

The area of ​​the lateral surface of a straight prism is found by the formula S side. = P main. · h = 4a\cdot h, where P main. and h, respectively, the perimeter of the base and the height of the prism, equal to 5, and a is the side of the rhombus. Let's find the side of the rhombus, using the fact that the diagonals of the rhombus ABCD are mutually perpendicular and the intersection point is divided in half.

I offer readers of "Habrahabr" a translation of the publication "100 Prisoners Escape Puzzle", which I found on the website of DataGenetics. Please send all errors in this article in private messages.

According to the condition of the problem, there are 100 prisoners in the prison, each of which has personal number from 1 to 100. The jailer decides to give the prisoners a chance for release and offers to pass the test he invented. If all the prisoners succeed, then they are free, if at least one fails, they all die.

A task

The jailer goes to the secret room and prepares 100 boxes with lids. On each box, he marks numbers from 1 to 100. Then he brings 100 paper tablets, according to the number of prisoners, and numbers these tablets from 1 to 100. After that, he shuffles 100 tablets and places one tablet in each box, closing the lid . The prisoners do not see how the jailer performs all these actions.

The competition begins, the jailer takes each prisoner one by one to the room with the boxes and tells the prisoners that they must find a box that will contain a plate with the number of the prisoner. The prisoners are trying to find the plate with their number by opening the boxes. Each is allowed to open up to 50 boxes; if each of the prisoners finds his number, then the prisoners will be released, if at least one of them does not find his number in 50 attempts, then all the prisoners will die.

In order for prisoners to be released, ALL prisoners must pass the test successfully.

So what is the chance that the prisoners will be pardoned?

  • After the prisoner opens the box and checks the plate, it is placed back in the box and the lid is closed again;
  • Places of the plates cannot be changed;
  • Prisoners cannot leave clues to each other or interact with each other in any way once the trial has begun;
  • Prisoners are allowed to discuss strategy before the trial begins.

What is the optimal strategy for prisoners?

Additional question:
If a friend of the prisoners (not a participant in the test) will be able to enter the secret room before the start of the test, examine all the tablets in all boxes and (optionally, but not required) swap two tablets from two boxes (in this case, the comrade will not have the opportunity to both inform the prisoners about the result of his actions), then what strategy should he take to increase the chances of the prisoners to escape?

Solution improbable?

At first glance, this task seems almost hopeless. It seems that the chance for each of the prisoners to find their tablet is microscopically small. In addition, prisoners cannot exchange information with each other during the trial.

The odds of one prisoner are 50:50. There are 100 boxes in total and he can open up to 50 boxes looking for his sign. If he opens the boxes at random and opens half of all the boxes, he will find his tablet in the open half of the boxes, or his tablet will remain in the closed 50 boxes. His chances of success are ½.

Let's take two prisoners. If both choose boxes at random, the chances for each of them will be ½, and for two ½x½=¼.
(for two prisoners, success will be in one case out of four).

For three prisoners, the odds are ½ × ½ × ½ = ⅛.

For 100 prisoners, the odds are: ½ × ½ × … ½ × ½ (multiply 100 times).

This equals

Pr ≈ 0.0000000000000000000000000000008

So it's a very small chance. In this scenario, most likely, all the prisoners will be dead.

Incredible answer

If each prisoner opens the boxes at random, they are unlikely to pass the test. There is a strategy where prisoners can expect to be successful more than 30% of the time. This is a stunningly incredible result (if you haven't heard of this math problem before).

More than 30% for all 100 prisoners! Yes, this is even more than the chances for two prisoners, provided that they open the boxes at random. But how is this possible?

It is clear that one for each prisoner, the chances cannot be higher than 50% (after all, there is no way for communication between prisoners). But do not forget that the information is stored in the location of the plates inside the boxes. No one shuffles the tablets between visits to the room by individual prisoners, so we can use that information.

Solution

First, I'll tell you the solution, then I'll explain why it works.

The strategy is extremely easy. The first of the prisoners opens the box with the number that is written on his clothes. For example, prisoner number 78 opens the box with the number 78. If he finds his number on the plate inside the box, that's great! If not, he looks at the number on the plate in "his" box and then opens the next box with that number. Having opened the second box, he looks at the number of the tablet inside this box and opens the third box with this number. Then we simply transfer this strategy to the remaining boxes. For clarity, look at the picture:

Eventually, the prisoner will either find his number or reach the 50 box limit. At first glance, this seems pointless compared to simply choosing a box at random (and for one individual prisoner it does), but since all 100 prisoners will be using the same set of boxes, it makes sense.

The beauty of this mathematical problem is not only to know the result, but also to understand why this strategy works.

So why does the strategy work?

Each box contains one plate - and this plate is unique. This means that the plate is in a box with the same number, or it points to a different box. Since all plates are unique, there is only one plate for each box pointing to it (and only one way to get to that box).

If you think about it, the boxes form a closed circular chain. One box can be part of only one chain, since inside the box there is only one pointer to the next one and, accordingly, in the previous box there is only one pointer to this box (programmers can see the analogy with linked lists).

If the box does not point to itself (the box number is equal to the plate number in it), then it will be in the chain. Some chains may consist of two boxes, some are longer.

Since all prisoners start with a box with the same number on their clothes, they are, by definition, placed on the chain that contains their nameplate (there is only one nameplate that points to this box).

Exploring the boxes along this chain in a circle, they are guaranteed to eventually find their plate.

The only question remains whether they will find their tablet in 50 moves.

Chain length

In order for all prisoners to pass the test, the maximum chain length must be less than 50 boxes. If the chain is longer than 50 boxes, prisoners with numbers from those chains will fail the test - and all prisoners will be dead.

If the maximum length of the longest chain is less than 50 boxes, then all prisoners will pass the test!

Think about it for a second. It turns out that there can only be one chain that is longer than 50 boxes in any layout of the plates (we have only 100 boxes, so if one chain is longer than 50, then the rest will be shorter than 50 in total).

Long chain hand odds

Once you've convinced yourself that the maximum chain length must be less than or equal to 50 to succeed, and there can only be one long chain in any set, we can calculate the probability of passing the challenge:

Some more math

So what do we need to figure out the probability of a long chain?

For a chain of length l, the probability that the boxes will be outside this chain is:

There is (l-1) in this collection of numbers! ways to arrange the signs.

The remaining signs can be located (100-l)! ways (do not forget that the length of the chain does not exceed 50).

Given this, the number of permutations that contain the chain exact length l: (>50)

It turns out that there are 100(!) ways to arrange the plates, so that the probability of existence of a chain of length l is equal to 1/l. By the way, this result does not depend on the number of boxes.

As we already know, there can only be one case in which there is a chain with a length > 50, so the probability of success is calculated by this formula:

Result

31.18% - the probability that the size of the longest chain will be less than 50 and each of the prisoners will be able to find their tablet, given the limit of 50 attempts.

The probability that all prisoners will find their plates and pass the test is 31.18%

Below is a graph showing the probabilities (on the y-axis) for all chains of length l (on the x-axis). Red means all "failures" (given curve here is just a 1/l plot). Green color means "success" (the calculation is a little more complicated for this part of the graph, since there are several ways to determine maximum length <50). Общая вероятность складывается из зеленых столбцов в 31.18% шанс на спасение.

Harmonic number (this part of the article is for geeks)

In mathematics, the nth harmonic number is the sum of the reciprocals of the first n consecutive numbers of the natural series.

Let's calculate the limit if instead of 100a boxes we have an arbitrary a large number of boxes (let's assume we have 2n boxes in total).

The Euler-Mascheroni constant is a constant defined as the limit of the difference between the partial sum of a harmonic series and the natural logarithm of a number.

As the number of prisoners increases, if the overseer allows prisoners to open half of all the boxes, then the chance of salvation tends to 30.685%

(If you make a decision in which the prisoners randomly guess the boxes, then as the number of prisoners increases, the probability of being saved tends to zero!)

Additional question

Anyone else remember the extra question? What can our helpful comrade do to increase our chances of survival?

Now we already know the solution, so the strategy here is simple: he must study all the signs and find the longest chain of boxes. If the longest chain is less than 50, then he does not need to change the tablets at all, or change them so that the longest chain does not become longer than 50. However, if he finds a chain longer than 50 boxes, all he has to do is swap the contents of two boxes from that chain to break that chain into two shorter chains.

As a result of this strategy, there will be no long chains and all prisoners are guaranteed to find their sign and salvation. So, by swapping two signs, we reduce the probability of salvation to 100%!

Question: Determine if one box will fit inside another


Condition: The dimensions of two boxes are given. Determine if one box will fit inside another?!

Answer:

Message from Joy

max 13 fit

No, not 13 ... To be precise, that is, approximately 12.7279 ... Putting a rectangle on a rectangle is a simple task ... But sticking a smaller box approximately along the largest diagonal of the larger box ... Yes . There's also a search for the right angles of rotation of a small box crawls out ...

Question: Can one of the boxes be placed inside the other?


For some reason it doesn't work, please help!
Here is the condition: There are two boxes, the first is A1×B1×C1, the second is A2×B2×C2. Determine if one of these boxes can be placed inside the other, provided that the boxes can only be rotated 90 degrees around the edges.
Input data format
The program receives numbers A1, B1, C1, A2, B2, C2 as input.
Output format
The program should output one of the following lines:
Boxes are equal if the boxes are the same,
The first box is smaller than the second one, if the first box can be placed in the second one,
The first box is larger than the second one, if the second box can be placed in the first one,
Boxes are incomparable, in all other cases.
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 #include "iostream" using namespace std; int main() ( int a1, a2, b1, b2, c1, c2, m, n, k, z, x, c; cin >> a1; cin >> b1; cin >> c1; cin >> a2; cin >> b2; cin >> c2; if ((a1 >= b1) && (a1 >= c1) && (b1 >= c1) ) ( m == a1; n == b1; k == c1; ) else ( if ((a1 >= b1) && (a1 >= c1) && (b1<= c1) ) { m = a1; n = c1; k = b1; } } if ((b1 >= a1) && (b1 >= c1) && (a1 >= c1) ) ( m = b1; n = a1; k = c1; ) else ( if ((b1 >= a1) && (b1 >= c1) && (c1 >= a1) ) ( m = b1; n = c1; k = a1; ) ) if ((c1 >= a1) && (c1 >= b1) && (b1 >= a1) ) ( m = c1; n = b1; k = a1; ) else ( if ((c1 >= a1) && (c1 >= b1) && (a1 >= b1) ) ( m = c1; n = a1; k = b1; ) ) if ((a2 >= b2) && (a2 >= c2) && (b2 >= c2) ) ( z = a2; x = b2; c = c2; ) else ( if ((a2 >= b2) && (a2 > = c2) && (b2<= c2) ) { z = a2; x = c2; c = b2; } } if ((b2 >= a2) && (b2 >= c2) && (a2 >= c2) ) ( z = b2; x = a2; c = c2; ) else ( if ((b2 >= a2) && (b2 >= c2) && (c2 >= a2) ) ( z = b2; x = c2; c = a2; ) ) if ((c2 >= a2) && (c2 >= b2) && (b2 >= a2) ) ( z = c2; x = b2; c = a2; ) else ( if ((c2 >= a2) && (c2 >= b2) && (a2 >= b2) ) ( z = c2; x = a2; c = b2; ) ) if ((m = z) && (n = x) && (k = c) ) ( cout<< "Boxes are equal" ; } else { if ((m >z) && (n > x) && (k > c) ) ( cout<< "The first box is larger than the second one"; ) else ( if ((m< z) && (n < x) && (k < c) ) { cout << "The first box is smaller than the second one"; ) else ( cout<< "Boxes are incomparable" ; } } } system ("pause" ) ; return 0 ; }

Answer: Dimension, Solution algorithm, first we sort the lengths of the sides of the boxes in order to compare them later, but! I need to do all this through an if statement, I will be very grateful if you write at least an algorithm, the code is somehow myself =)

Question: Open one form inside another


Good day to all. I’m writing a program and I can’t figure out how to open Form2 in Form1 on half of the form inside, etc. when you click on the button in MenuStrip1 as in the screenshot.

Screenshot:

There is a code:

vb.net
1 2 3 4 Private Sub Command1_Click() Form2. Visible = True Form1. Visible = False End Sub

But it opens the form of the program separately, and I need the Form2, Form3 window to open in Form1 itself (not on the entire form), and so on.

Answer: Thank you very much, everything worked out

Now I will write the stuffing of the program.

Added after 22 hours 49 minutes
I ran into such a problem yesterday (I tried to solve it myself all evening, but it didn’t work out), the code is working, everything is fine. But here's the trouble, I can't switch between Form2 Form3 and so on (in reverse order) what can I add to this code?

vb.net
1 2 3 4 5 6 7 8 9 10 Private Sub Form1_Load(ByVal sender As System. Object , ByVal e As System. EventArgs ) Handles MyBase . Load me. IsMdiContainer = True End Sub Private Sub ArmorToolStripMenuItem_Click(sender As Object , e As EventArgs) Handles ArmorToolStripMenuItem. Click Form2. MdiParent = MeForm2. Show() Form2. Location = New Point((0 ) - (0 ) , 0 ) Form2. ControlBox = False End Sub

That is, I need to switch between Armor, Power armor, etc. (project screen above)

Thank you in advance.

Added after 32 minutes
All found a solution

You just need to add a line.

vb.net
1 Form3. visible = false

Question: Passing the selected position in the datagrid from one form to another


Good afternoon.
Interested in the possibility of transferring the current selected position to the datagrid (+ BindingSource is used, in fact, all data is located in tables in the MSSQL database) located on one form to another datagrid of another form.

What is the essence, on the main form there is a datagrid, let's say with a list of full names. We choose, for example, the second surname. Then, on an additionally opening form, in another datagrid, all things owned by this full name should open. Therefore, if we select the third last name in the list, then in the additional form with our datagrid there will already be data for this full name.
Inside one form, this can be implemented with relationships (dataSet.Relations.Add), but when creating an additional form, the second form does not know what position is selected in the datagrid on the first form.
Thanks.

Answer:

Message from gmaxim

In the first form, we insert after InitializeComponent(); given item:

And why is he there???

Message from gmaxim

SELECT " + id + " FROM Tables2

This query will definitely not work.

Message from gmaxim

How to do this, I've been telling you all day!

Message from Datsend

If you're lazy/no time/don't want to, you can look at How to transfer data from one form to another

Since this all started!!! None of these options matched!

Question: How to open one form inside another, so that the child does not go beyond the parent?


I try this (read in this forum) swears "The form specified as MdiParent for this form is not MdiContainer."

Tell me, please, how to do it?

Added after 1 hour 4 minutes
Here I understood how it was necessary to assign the parent form to the isMDIContainer property true.
Now another problem, writes that it is impossible to create a modal form inside this container, but I just need a modal form

Answer: And yet, what to do if you need a child modal form?
Those. is it necessary that, on the one hand, the form be placed within the parent (main window of the application), and on the other hand, that the entire application "freezes" until the end of work with it?

Question: Given two words, determine whether the letters of one word can be formed into another


Given two words, determines whether the letters of one word can be used to form another

Answer: The condition of the problem says. Is it possible from the letters of one
words to make another. But nothing is said about
that the words must be of equal length. In other words
task can be interpreted as follows. Is it possible to
from the letters of one word to form another Any Length
as long as there are enough letters.
There is such a game from one long word to compose
a bunch of smaller ones. (pro. verified)
the first word is the most important. The second is being built from it ...

QBasic/QuickBASIC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 CLS DIM s1 AS STRING DIM s2 AS STRING DIM s AS STRING INPUT "SLOVO_1 = " ; s1 INPUT "SLOVO_2 = " ; s2 FOR i = 1 TO LEN (s1) s = MID$ (s2, i, 1 ) k = INSTR (s1, s) IF k THEN MID$ (s1, k, 1 ) = " " ELSE PRINT "NO" : END END IF NEXT i PRINT "YES" END

Question: Pass a pointer to a function from one class to another


Good day. I rummaged for a long time on the forum and on the internet in general, but did not find an answer to the question: how to pass a pointer to a function from one class to another. The gist is this:

There is "Class1", it has a method "Method"
There is a "Class2" whose objects are created in the class "Class1"

The bottom line is that "Class2" should be able to call "Method". I think the easiest way to do this is by passing a pointer to "Method" to "Class2". But it turned out not to be so simple. Can you please demonstrate how this can be done. Well, or maybe there is an easier way to call the "Method" registered in "Class1" from "Class2".

Answer: Hmm. Everything would be easier if the class method had to be called in main, and since this is a different class, everything is completely bad. In principle, I assumed such an outcome from the very beginning, but I thought that it could be simpler. Okay, thanks for that)

Added after 18 hours 1 minute
I found, thanks to Stack Overflow (), a simpler and less cumbersome method of passing a pointer from one class to another:

C++
1 2 3 4 aircraft Aircraft; boer Boer; Boer.setSomeFun ([ & ] (int v) ( Aircraft.source_forSomeFun (v) ; ) ) ;

Answer: 1. Using the MVVM pattern, you can refer to the ViewModel of the View from which we want to get data (point 3 is shorter, MVVM is just convenient to create on WPF, judging by the statements).
2. Hmm... Static class, methods, variables, properties. Pass data from one form to another through a static class.
3. As a result, I see a solution in separating the view from the model (in general). Using one of these may solve your problem.

Cars with a manual transmission, which is abbreviated as manual transmission, until recently made up the vast majority among other vehicles with different ones.

Moreover, a mechanical (manual) box remains a fairly common device for changing and transmitting engine torque today. Next, we will talk about how the "mechanics" is arranged and works, what the gearbox scheme of this type looks like, and also what advantages and disadvantages this solution has.

Read in this article

Manual transmission diagram and features

To begin with, this type of gearbox is called mechanical due to the fact that such a unit involves manual gear shifting. In other words, on cars with manual transmission, the driver himself switches gears.

We go further. The "mechanics" box is stepped, that is, the torque changes in steps. Many motorists know that the gearbox actually has gears and shafts, but not everyone understands how the unit works.

So, a stage (it is also a transmission) is a pair of gears (driving and driven gear) interacting with each other. Each such stage provides rotation with one or another angular velocity, that is, it has its own gear ratio.

Under the gear ratio should be understood as the ratio of the number of teeth of the driven gear to the number of teeth on the drive gear. In this case, different stages of the box receive different gear ratios. The lowest gear (low gear) has the largest gear ratio and the highest gear (high gear) has the smallest gear ratio.

It becomes clear that the number of steps is equal to the number of gears on a particular box (four-speed gearbox, five-speed, etc.) previously 4-speed manual transmissions have gradually faded into the background.

Manual transmission device

So, although there can be many designs of such a box with certain features, however, at the initial stage, two main types can be distinguished:

  • three-shaft gearboxes;
  • two-shaft boxes;

A three-shaft manual gearbox is usually installed on rear-wheel drive cars, while a two-shaft gearbox is placed on front-wheel drive passenger cars. At the same time, the device of mechanical gearboxes of both the first and second types can differ markedly.

Let's start with a three-shaft mechanical box. This box contains:

  • the drive shaft, which is also called the primary;
  • intermediate shaft gearbox;
  • driven shaft (secondary);

Gears with synchronizers are installed on the shafts. The gearshift mechanism is also included in the gearbox. These components are located in the gearbox housing, which is also called the gearbox housing.

The task of the drive shaft is to create a connection with the clutch. The drive shaft has slots for the clutch disc. As for the torque, the specified torque from the input shaft is transmitted through the gear, which is in rigid engagement with it.

Affecting the work of the intermediate shaft, this shaft is located parallel to the input shaft of the gearbox, a group of gears is installed on it, which is in rigid engagement. In turn, the driven shaft is mounted on the same axis as the drive shaft.

Such an installation is implemented using an end bearing on the drive shaft. This bearing includes the driven shaft. The group of gears (gear block) on the driven shaft does not have a rigid engagement with the shaft itself and therefore rotates freely on it. In this case, the group of gears of the intermediate shaft, the driven shaft and the gear of the drive shaft are in constant engagement.

Synchronizers (synchronizer couplings) are installed between the gears of the driven shaft. Their task is to align the angular velocities of the gears of the driven shaft with the angular velocity of the shaft itself through the force of friction.

Synchronizers are in rigid engagement with the driven shaft, and also have the ability to move along the shaft in the longitudinal direction due to the spline connection. Modern gearboxes have synchronizer clutches in all gears.

If we consider the gearshift mechanism on three-shaft gearboxes, often this mechanism is installed on the unit body. The design includes a control lever, sliders and forks.

The box body (crankcase) is made of aluminum or magnesium alloys, it is necessary for installing shafts with gears and mechanisms, as well as a number of other parts. There is also gear oil (gearbox oil) in the gearbox housing.

  • To understand how a three-shaft type mechanical (manual) gearbox works, let's look at the principle of its operation in general terms. When the gear lever is in the neutral position, there is no transmission of torque from the engine to the vehicle's drive wheels.

After the driver moves the lever, the fork will move the synchronizer clutch of one or another gear. Then the synchronizer will align the angular speeds of the desired gear and the driven shaft. Then the gear ring of the clutch will engage with a similar gear ring, which will ensure that the gear is locked on the driven shaft.

We also add that the reverse gear of the car is provided by the reverse gear of the gearbox. In this case, a reverse idle gear mounted on a separate axle allows the direction of rotation to be reversed.

Two-shaft manual gearbox: device and principle of operation

Having dealt with what a three-shaft gearbox consists of, let's move on to two-shaft gearboxes. This type of gearbox has two shafts in its device: primary and secondary. The input shaft is the driving one, the secondary is the driven one. Gears and synchronizers are fixed on the shafts. Also in the crankcase of the box is the main gear and differential.

The drive shaft is responsible for connecting with the clutch, and there is also a gear block on the shaft in rigid engagement with the shaft. The driven shaft is located parallel to the drive shaft, while the gears of the driven shaft are in constant engagement with the gears of the drive shaft, and also rotate freely on the shaft itself.

Also, the drive gear of the main gear is rigidly fixed on the driven shaft, and synchronizer couplings are located between the gears of the driven shaft. We add, in order to reduce the size of the gearbox, as well as increase the number of gears, in modern gearboxes, 2 or even 3 shafts can often be installed instead of one driven shaft.

On each such shaft, the gear of the main gear is rigidly fixed, while such a gear has a rigid engagement with the driven gear. It turns out that the design actually implements 3 main gears.

The main gear itself, as well as the differential in the gearbox device, transmit torque from the secondary shaft to the drive wheels. In this case, the differential can also provide such rotation of the wheels when the drive wheels rotate at different angular speeds.

As for the gearshift mechanism, on two-shaft gearboxes it is taken out separately, that is, outside the body. The box is connected to the switching mechanism by cables or special rods. The most common connection is with cables.

The shift mechanism of the 2-shaft box itself has a lever, which is connected by cables to the selector lever and the gear shift lever. These levers are connected to the central shift rod, which also has forks.

  • If we talk about the principle of operation of a two-shaft manual gearbox, it is similar to the principle of a three-shaft gearbox. The differences are in how the gearshift mechanism works. In a nutshell, the lever can carry out both longitudinal and transverse movements relative to the axis of the car. During lateral movement, gear selection occurs as force is applied to the gear selection cable, which acts on the gear selector lever.

Further, the lever moves longitudinally, and the force goes to the gearshift cable. The corresponding lever horizontally moves the stem with the forks, the fork on the stem displaces the synchronizer, which leads to blocking of the driven shaft gear.

Finally, we note that also mechanical boxes of different types have additional blocking devices that prevent the inclusion of two gears at the same time or an unexpected gear disengagement.

Read also

Depressing the clutch before starting the engine: when to depress the clutch and in what cases it is not recommended to do so. Useful tips and tricks.

  • Causes of difficult gear shifting on a running engine. Transmission oil and level in the gearbox, wear of synchronizers and gears of the box, clutch.


  • Views