Guest User

HARDCORE_LABA_02.pas

a guest
Oct 29th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.70 KB | None | 0 0
  1. var
  2.   input, output: string;
  3.   endpoint, size: integer;
  4.   I, J, K, L: integer;
  5.   dirright: boolean;
  6.   arr: array of array of char;
  7. begin
  8.   try
  9.     readln(input);
  10.     endpoint := pos('.', input);
  11.     if (endpoint < 1) or (length(input) = 0) then
  12.       writeln('Входная строка имела неверный формат.')
  13.     else
  14.       begin
  15.         input := copy(input, 1, endpoint - 1);
  16.         size := ceil(sqrt(length(input)));
  17.         setlength(arr, size, size);
  18.         for I := 0 to size - 1 do
  19.             for J := 0 to size - 1 do
  20.               begin
  21.                 if (I * size) + (J + 1) <= endpoint - 1 then
  22.                   arr[I, J] := input[(I * size) + (J + 1)]
  23.                 else
  24.                   arr[I, J] := '#';
  25.               end;
  26.  
  27.         K := 0;
  28.         L := 0;
  29.         I := 0;
  30.         J := 0;
  31.         while (k < size) and (l < size) do
  32.           begin
  33.  
  34.             output := output + arr[j, i];
  35.             if not dirright then
  36.             begin
  37.               j := j + 1;
  38.               if j > size - 1 then
  39.               begin
  40.                 k := k + 1;
  41.                 dirright := true;
  42.                 i := k;
  43.                 j := l;
  44.               end;
  45.             end
  46.               else
  47.                 begin
  48.                   i := i + 1;
  49.                   if i > size - 1 then
  50.                     begin
  51.                       l := l + 1;
  52.                       dirright := false;
  53.                       i := k;
  54.                       j := l;
  55.                     end;
  56.             end
  57.           end;
  58.  
  59.         writeln(output);
  60.         read;
  61.       end;
  62.  
  63.   except
  64.     on E: Exception do
  65.       Writeln(E.ClassName, ': ', E.Message);
  66.   end;
Advertisement
Add Comment
Please, Sign In to add comment