Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8.   function File_size(fileName:string):integer;
  9.   var
  10.     j:Integer;
  11.   fileMain:TextFile;
  12.   buf:string;
  13.     begin
  14.      AssignFile(FileMain,FileName);
  15.       Reset(FileMain);
  16.       result:=0;
  17.       while not Eof(FileMain) do
  18.         begin
  19.          Readln(Filemain,buf);
  20.          Result:=result+1;
  21.         end;
  22.     end;
  23.  
  24.   function Seek_my(fileName:string;i:Integer):string;
  25.   var j:Integer;
  26.   fileMain:TextFile;
  27.     begin
  28.       AssignFile(FileMain,FileName);
  29.       Reset(FileMain);
  30.       j:=1;
  31.       while (j<i+1) do
  32.       begin
  33.       Readln(FileMain,result);
  34.       result:=Trim(result);
  35.       j:=j+1;
  36.       end;
  37.      CloseFile(FileMain);
  38.  
  39.       end;
  40.  
  41.   function switch_to(File_Name:string;from:Integer):integer;
  42.   var
  43.      close_skobka,open_skobka:integer;
  44.      count_open:integer;
  45.      count_close:Integer;
  46.      buf2:string;
  47.     flag_close_end,flag_close_pred:Boolean;
  48.     begin
  49.       open_skobka:=from;
  50.           flag_close_pred:=False;
  51.           flag_close_end:=False;
  52.  
  53.           close_skobka:=open_skobka;
  54.  
  55.           buf2:=Seek_my(File_Name,close_skobka);
  56.  
  57.            if Pos('}',buf2)<>0   then
  58.             begin
  59.             flag_close_end:=True;
  60.             end else close_skobka:=open_skobka+1;
  61.           count_open:=1;
  62.           count_close:=0;
  63.           buf2:=Seek_my(File_Name,close_skobka);
  64.           while not(flag_close_end) do
  65.           begin
  66.  
  67.  
  68.            if Pos('{',buf2)<>0 then
  69.             begin
  70.             count_open:=count_open+1;
  71.             end;
  72.            if Pos('}',buf2)<>0 then
  73.             begin
  74.             count_close:=count_close+1;
  75.             end;
  76.           if count_close = count_open then
  77.             begin
  78.              flag_close_end:=True;
  79.             end;
  80.  
  81.            close_skobka:=close_skobka+1;
  82.            buf2:=Seek_my(File_Name,close_skobka);
  83.           end;
  84.           result:=close_skobka-1;
  85.     end;
  86.  
  87.     function Count_in(fileName:string;from:integer;k:integer):Integer;
  88.     label  mark;
  89.     var
  90.       i:integer;
  91.      buf:string;
  92.     Arr_count:array of Integer;
  93.     Max:integer;
  94.     flag_now:Boolean;
  95.     flag_pred:boolean;
  96.     j:integer;
  97.     sw:string;
  98.     sw_l:integer;
  99.     flag_sw:Boolean;
  100.     count_case:integer;
  101.     flag_case_open:boolean;
  102.     sw_in:integer;
  103.     case_number:integer;
  104.     before_sw:integer;
  105.     begin
  106.      sw:='switch';
  107.      flag_sw:=False;
  108.      Result:=0;
  109.      SetLength(Arr_count,File_size(fileName));
  110.      for i:=0 to Length(Arr_count)-1 do
  111.       begin
  112.         Arr_count[i]:=0;
  113.       end;
  114.  
  115.      while (Pos('{',buf)=0) and (from<=k) do
  116.       begin
  117.       buf:=Seek_my(fileName,from);
  118.       if (Pos('{',buf)=0) then
  119.       begin
  120.       from:=from+1;
  121.       end else flag_now:=True;
  122.       end;
  123.       from:=from+1;
  124.       i:=0;
  125.       flag_case_open:=False;
  126.       while from<=k do
  127.         begin
  128.           buf:=Seek_my(fileName,from);
  129.  
  130.           if from=sw_l then
  131.               begin
  132.               flag_sw:=false;
  133.               end;
  134.  
  135.           if Pos(sw,buf)<>0 then
  136.             begin
  137.               flag_sw:=True;
  138.               sw_l:=switch_to(fileName,from+1);
  139.               before_sw:= Arr_count[i];
  140.               case_number:=0;
  141.             end;
  142.  
  143.              if (Pos('case',buf)<>0) then
  144.             begin
  145.               case_number:=case_number+1;
  146.               flag_pred:=flag_now;
  147.               flag_now:=True;
  148.               Arr_count[i]:=Arr_count[i]+1;
  149.               i:=i+1;
  150.               Arr_count[i]:=case_number+before_sw;
  151.  
  152.             end;
  153.  
  154.  
  155.           if (Pos('{',buf)<>0) then
  156.             begin
  157.               flag_pred:=flag_now;
  158.               flag_now:=True;
  159.               Arr_count[i]:=Arr_count[i]+1;
  160.             end;
  161.  
  162.             if  (Pos('while',buf)<>0) and ( (Pos('while',Seek_my(fileName,from+1))<>0)or (Pos('if',Seek_my(fileName,from+1))<>0) or (Pos('for',Seek_my(fileName,from+1))<>0) or (Pos('else',Seek_my(fileName,from+1))<>0)) and  (Pos('{',buf)=0)  then
  163.             begin
  164.               Arr_count[i]:=Arr_count[i]+1;
  165.  
  166.             end;
  167.  
  168.              if  (Pos('if',buf)<>0) and ( (Pos('if',Seek_my(fileName,from+1))<>0) or  (Pos('while',Seek_my(fileName,from+1))<>0) or (Pos('for',Seek_my(fileName,from+1))<>0) or (Pos('else',Seek_my(fileName,from+1))<>0)) and  (Pos('{',buf)=0) then
  169.             begin
  170.               Arr_count[i]:=Arr_count[i]+1;
  171.  
  172.             end;
  173.  
  174.              if (Pos('for',buf)<>0) and ( (Pos('for',Seek_my(fileName,from+1))<>0) or (Pos('if',Seek_my(fileName,from+1))<>0) or (Pos('while',Seek_my(fileName,from+1))<>0) or (Pos('else',Seek_my(fileName,from+1))<>0)) and  (Pos('{',buf)=0) then
  175.             begin
  176.               Arr_count[i]:=Arr_count[i]+1;
  177.  
  178.             end;
  179.  
  180.              if(Pos('else',buf)<>0) and ( (Pos('else',Seek_my(fileName,from+1))<>0) or (Pos('if',Seek_my(fileName,from+1))<>0) or (Pos('for',Seek_my(fileName,from+1))<>0) or (Pos('while',Seek_my(fileName,from+1))<>0)) and  (Pos('{',buf)=0) then
  181.             begin
  182.               Arr_count[i]:=Arr_count[i]+1;
  183.  
  184.             end;
  185.  
  186.  
  187.  
  188.  
  189.  
  190.             if (Pos('}',buf)<>0)  then
  191.             begin
  192.               flag_pred:=flag_now;
  193.               flag_now:=False;
  194.  
  195.               if flag_sw then
  196.               begin
  197.               i:=i+1;
  198.               Arr_count[i+1]:=Arr_count[i]-1;
  199.               end;
  200.             end;
  201.  
  202.         from:=from+1;
  203.        end;
  204.         Max:=0;
  205.        for i:=0 to Length(Arr_count)-1 do
  206.         begin
  207.         if Max<Arr_count[i] then
  208.           begin
  209.            Max:=Arr_count[i];
  210.           end;
  211.         end;
  212.         if Result<Max then result:=Max;
  213.     end;
  214.  
  215.  
  216.  
  217. function  Count_Vlog(File_Name:String):Integer;
  218. const n=3;
  219.   var
  220.    FileMain: TextFile;
  221.    var buf,buf2:string;
  222.    i:integer;
  223.    count:Integer;
  224.    flag:Boolean;
  225.  
  226.    flag_open:Boolean;
  227.    flag_close:Boolean;
  228.    flag_close_pred:Boolean;
  229.    flag_close_end:boolean;
  230.    open_skobka:Integer;
  231.    close_skobka:integer;
  232.    position:Integer;
  233.    count_line:integer;
  234.    name_with_skobka:string;
  235.    Count_open:Integer;
  236.    count_close:Integer;
  237.    max:Integer;
  238.    All_oper: array[1..5] of string;
  239.     begin
  240.       Result:=0;
  241.        All_oper[1]:='for';
  242.        All_oper[2]:='while';
  243.        All_oper[3]:='if';
  244.        All_oper[4]:='else';
  245.        All_oper[5]:='do';
  246.  
  247.     position:=1;
  248.     count:=0;
  249.     count_line:=File_size(File_Name);
  250.  
  251.     while position<count_line+1 do
  252.       begin
  253.       buf:=Seek_my(file_name,position);
  254.       for i:=1 to 5 do
  255.         begin
  256.          if Pos(All_oper[i],buf) <> 0 then
  257.           begin
  258.           name_with_skobka:=All_oper[i];
  259.           Break;
  260.           end;
  261.         end;
  262.       if Pos(name_with_skobka,buf) <> 0 then
  263.         begin
  264.  
  265.         buf:=Seek_my(file_name,position);
  266.         open_skobka:=position;
  267.           if Pos('{',buf)=0 then
  268.             begin
  269.              //open_skobka- открытие внешней скобки
  270.              buf2:=Seek_my(file_name,open_skobka);
  271.  
  272.               while Pos('{',buf2)=0  do
  273.                 begin
  274.                   if Pos('{',buf2)=0 then open_skobka:=open_skobka+1;
  275.                   buf2:=Seek_my(file_name,open_skobka);
  276.                 end;
  277.  
  278.             end ;
  279.           flag_close_pred:=False;
  280.           flag_close_end:=False;
  281.  
  282.           close_skobka:=open_skobka;
  283.  
  284.           buf2:=Seek_my(File_Name,close_skobka);
  285.  
  286.            if Pos('}',buf2)<>0   then
  287.             begin
  288.             flag_close_end:=True;
  289.             end else close_skobka:=open_skobka+1;
  290.           count_open:=1;
  291.           count_close:=0;
  292.           buf2:=Seek_my(File_Name,close_skobka);
  293.           while not(flag_close_end) do
  294.           begin
  295.  
  296.  
  297.            if Pos('{',buf2)<>0 then
  298.             begin
  299.             count_open:=count_open+1;
  300.             end;
  301.            if Pos('}',buf2)<>0 then
  302.             begin
  303.             count_close:=count_close+1;
  304.             end;
  305.           if count_close = count_open then
  306.             begin
  307.              flag_close_end:=True;
  308.             end;
  309.  
  310.            close_skobka:=close_skobka+1;
  311.            buf2:=Seek_my(File_Name,close_skobka);
  312.           end;
  313.  
  314.          max:=Count_in('In_put_count.txt',open_skobka,close_skobka-1) ;
  315.          if Result<max then result:=max;
  316.          if name_with_skobka='do' then position:=close_skobka-1
  317.          else position:=close_skobka-1;
  318.  
  319.  
  320.         end;
  321.       position:=position+1;
  322.       end;
  323.  
  324.  
  325.  
  326.     end;
  327.  
  328.  
  329.  
  330. begin
  331.  Writeln( Count_Vlog('In_put_count.txt'));
  332.   //Writeln(Seek_my('In_put_count.txt',2));
  333.   //Count_in('In_put_count.txt',2,9) ;
  334.   Readln;
  335.   { TODO -oUser -cConsole Main : Insert code here }
  336. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement