Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.07 KB | None | 0 0
  1. Program Laba3_2;
  2. uses
  3.   System.SysUtils;
  4. {$APPTYPE CONSOLE}
  5.  
  6. Const
  7.     nMin = 2;
  8.     nMax = 10;
  9.     lengthMin = 1;
  10.     lengthMax = 40;
  11. Type
  12.     Variety = set of Char;
  13.     TArr = array[1..nmax] of String[lengthMax];
  14.     TArrOfVariety = array[1..nmax] of Variety;
  15.  
  16. Procedure Condition();
  17. Begin
  18.     Writeln('This program converts a string according to the rule: ');
  19.     Writeln('1)If the string length > N, then the program will discard the first characters.');
  20.     Writeln('2)If the string length < N, then the program will add "."');
  21. End;
  22.  
  23. Function ChoiseInput(): Char;
  24. Var
  25.     Input: Char;
  26.     IsCorrect: Boolean;
  27. Begin
  28.     Repeat
  29.         Readln(Input);
  30.         Input := UpCase(Input);
  31.         if ((Input = 'Y') or (Input = 'N')) then
  32.             IsCorrect := True
  33.         else
  34.         Begin
  35.             IsCorrect := False;
  36.             Writeln('Incorrect input. Enter Y(Yes) or N(No): ');
  37.         End;
  38.     Until IsCorrect;
  39.     ChoiseInput := Input;
  40. End;
  41.  
  42. Function CheckInput(): Integer;
  43. Var
  44.     N: Integer;
  45.     IsCorrect: Boolean;
  46. Begin
  47.     IsCorrect := False;
  48.     Repeat
  49.         Try
  50.             Readln(N);
  51.             if ((N >= nMin) and (N <= nMax)) then
  52.                 IsCorrect := True
  53.             else
  54.                 Writeln('Enter number from interval [',nMin,'...',nMax,']: ');
  55.         Except
  56.             Writeln('Check entered data. Enter number from interval [',nMin,'...',nMax,']: ');
  57.         End;
  58.     Until IsCorrect;
  59.     CheckInput := N;
  60. End;
  61.  
  62. Function CheckInputString(): String;
  63. Var
  64.     IsCorrect: Boolean;
  65.     Sentence: String;
  66. Begin
  67.     Repeat
  68.         Readln(Sentence);
  69.         if ((Length(Sentence) >= lengthMin) and (Length(Sentence) <= lengthMax)) then
  70.             IsCorrect := True
  71.         else
  72.         Begin
  73.             Writeln('Enter string length from interval [',lengthMin,'...',lengthMax,']: ');
  74.             IsCorrect := False;
  75.         End;
  76.     Until IsCorrect;
  77.     CheckInputString := Sentence;
  78. End;
  79.  
  80. Function InputNumFromConsole(): integer; //Ввод N с консоли
  81. Var
  82.     n: integer;
  83. Begin
  84.     Writeln('Введите количество строк: ');
  85.     n := checkInput();
  86.     InputNumFromConsole := n;
  87. End;
  88.  
  89. Function InputFromConsole(n: integer): TArr;
  90. Var
  91.     ArrOfString: TArr;
  92.     i,j: integer;
  93. Begin
  94.     Writeln('Введите количество строк: ');
  95.     n := checkInput();
  96.     For i := 1 to n do
  97.     Begin
  98.         Writeln('Введите ',i,' строку: ');
  99.         ArrOfString[i] := checkInputString();
  100.     End;
  101.     InputFromConsole := ArrOfString;
  102. End;
  103.  
  104. Var
  105.     mass: array[1..nmax] of String[lengthMax];
  106.     massOfVariety: array[1..nmax] of Variety;
  107.     n: integer;
  108.     i,j,k: byte;
  109.     isAllString: boolean;
  110. Begin
  111.     Writeln('Введите количество строк: ');
  112.     n := checkInput();
  113.     For i := 1 to n do
  114.     Begin
  115.         Writeln('Введите ',i,' строку: ');
  116.         mass[i] := checkInputString();
  117.         For j := 1 to length(mass[i]) do
  118.             include(massOfVariety[i],mass[i,j]);
  119.     End;
  120.  
  121.     Writeln('Исходный массив строк: ');
  122.     for I := 1 to n do
  123.     begin
  124.         Write('[',i,']: ',mass[i]);
  125.         Writeln;
  126.     end;
  127.  
  128.     isAllString := false;
  129.     i := 1;
  130.     while ((i <= n) and (not isAllString)) do
  131.     begin
  132.         k:=0;
  133.         for j:=1 to n do
  134.         Begin
  135.             if (massOfVariety[j] + massOfVariety[i] = massOfVariety[j]) then
  136.                 k:=k+1;
  137.         End;
  138.         if (k = n) then
  139.         begin
  140.             isAllString:=true;
  141.             write('Множество, являющееся подмножеством всех множеств: ');
  142.             for k:=1 to 255 do
  143.             Begin
  144.                 if chr(k) in massOfVariety[i] then
  145.                     write(chr(k));
  146.             End;
  147.             writeln;
  148.             writeln('Порядковый номер множества: ',i);
  149.         end
  150.         else
  151.             i:=i+1;
  152.     end;
  153.     if (not IsAllString) then
  154.         write('Такого множества нет');
  155.     readln;
  156. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement