Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- function File_size(fileName:string):integer;
- var
- j:Integer;
- fileMain:TextFile;
- buf:string;
- begin
- AssignFile(FileMain,FileName);
- Reset(FileMain);
- result:=0;
- while not Eof(FileMain) do
- begin
- Readln(Filemain,buf);
- Result:=result+1;
- end;
- end;
- function Seek_my(fileName:string;i:Integer):string;
- var j:Integer;
- fileMain:TextFile;
- begin
- AssignFile(FileMain,FileName);
- Reset(FileMain);
- j:=1;
- while (j<i+1) do
- begin
- Readln(FileMain,result);
- result:=Trim(result);
- j:=j+1;
- end;
- CloseFile(FileMain);
- end;
- function switch_to(File_Name:string;from:Integer):integer;
- var
- close_skobka,open_skobka:integer;
- count_open:integer;
- count_close:Integer;
- buf2:string;
- flag_close_end,flag_close_pred:Boolean;
- begin
- open_skobka:=from;
- flag_close_pred:=False;
- flag_close_end:=False;
- close_skobka:=open_skobka;
- buf2:=Seek_my(File_Name,close_skobka);
- if Pos('}',buf2)<>0 then
- begin
- flag_close_end:=True;
- end else close_skobka:=open_skobka+1;
- count_open:=1;
- count_close:=0;
- buf2:=Seek_my(File_Name,close_skobka);
- while not(flag_close_end) do
- begin
- if Pos('{',buf2)<>0 then
- begin
- count_open:=count_open+1;
- end;
- if Pos('}',buf2)<>0 then
- begin
- count_close:=count_close+1;
- end;
- if count_close = count_open then
- begin
- flag_close_end:=True;
- end;
- close_skobka:=close_skobka+1;
- buf2:=Seek_my(File_Name,close_skobka);
- end;
- result:=close_skobka-1;
- end;
- function Count_in(fileName:string;from:integer;k:integer):Integer;
- label mark;
- var
- i:integer;
- buf:string;
- Arr_count:array of Integer;
- Max:integer;
- flag_now:Boolean;
- flag_pred:boolean;
- j:integer;
- sw:string;
- sw_l:integer;
- flag_sw:Boolean;
- count_case:integer;
- flag_case_open:boolean;
- sw_in:integer;
- case_number:integer;
- before_sw:integer;
- begin
- sw:='switch';
- flag_sw:=False;
- Result:=0;
- SetLength(Arr_count,File_size(fileName));
- for i:=0 to Length(Arr_count)-1 do
- begin
- Arr_count[i]:=0;
- end;
- while (Pos('{',buf)=0) and (from<=k) do
- begin
- buf:=Seek_my(fileName,from);
- if (Pos('{',buf)=0) then
- begin
- from:=from+1;
- end else flag_now:=True;
- end;
- from:=from+1;
- i:=0;
- flag_case_open:=False;
- while from<=k do
- begin
- buf:=Seek_my(fileName,from);
- if from=sw_l then
- begin
- flag_sw:=false;
- end;
- if Pos(sw,buf)<>0 then
- begin
- flag_sw:=True;
- sw_l:=switch_to(fileName,from+1);
- before_sw:= Arr_count[i];
- case_number:=0;
- end;
- if (Pos('case',buf)<>0) then
- begin
- case_number:=case_number+1;
- flag_pred:=flag_now;
- flag_now:=True;
- Arr_count[i]:=Arr_count[i]+1;
- i:=i+1;
- Arr_count[i]:=case_number+before_sw;
- end;
- if (Pos('{',buf)<>0) then
- begin
- flag_pred:=flag_now;
- flag_now:=True;
- Arr_count[i]:=Arr_count[i]+1;
- end;
- 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
- begin
- Arr_count[i]:=Arr_count[i]+1;
- end;
- 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
- begin
- Arr_count[i]:=Arr_count[i]+1;
- end;
- 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
- begin
- Arr_count[i]:=Arr_count[i]+1;
- end;
- 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
- begin
- Arr_count[i]:=Arr_count[i]+1;
- end;
- if (Pos('}',buf)<>0) then
- begin
- flag_pred:=flag_now;
- flag_now:=False;
- if flag_sw then
- begin
- i:=i+1;
- Arr_count[i+1]:=Arr_count[i]-1;
- end;
- end;
- from:=from+1;
- end;
- Max:=0;
- for i:=0 to Length(Arr_count)-1 do
- begin
- if Max<Arr_count[i] then
- begin
- Max:=Arr_count[i];
- end;
- end;
- if Result<Max then result:=Max;
- end;
- function Count_Vlog(File_Name:String):Integer;
- const n=3;
- var
- FileMain: TextFile;
- var buf,buf2:string;
- i:integer;
- count:Integer;
- flag:Boolean;
- flag_open:Boolean;
- flag_close:Boolean;
- flag_close_pred:Boolean;
- flag_close_end:boolean;
- open_skobka:Integer;
- close_skobka:integer;
- position:Integer;
- count_line:integer;
- name_with_skobka:string;
- Count_open:Integer;
- count_close:Integer;
- max:Integer;
- All_oper: array[1..5] of string;
- begin
- Result:=0;
- All_oper[1]:='for';
- All_oper[2]:='while';
- All_oper[3]:='if';
- All_oper[4]:='else';
- All_oper[5]:='do';
- position:=1;
- count:=0;
- count_line:=File_size(File_Name);
- while position<count_line+1 do
- begin
- buf:=Seek_my(file_name,position);
- for i:=1 to 5 do
- begin
- if Pos(All_oper[i],buf) <> 0 then
- begin
- name_with_skobka:=All_oper[i];
- Break;
- end;
- end;
- if Pos(name_with_skobka,buf) <> 0 then
- begin
- buf:=Seek_my(file_name,position);
- open_skobka:=position;
- if Pos('{',buf)=0 then
- begin
- //open_skobka- открытие внешней скобки
- buf2:=Seek_my(file_name,open_skobka);
- while Pos('{',buf2)=0 do
- begin
- if Pos('{',buf2)=0 then open_skobka:=open_skobka+1;
- buf2:=Seek_my(file_name,open_skobka);
- end;
- end ;
- flag_close_pred:=False;
- flag_close_end:=False;
- close_skobka:=open_skobka;
- buf2:=Seek_my(File_Name,close_skobka);
- if Pos('}',buf2)<>0 then
- begin
- flag_close_end:=True;
- end else close_skobka:=open_skobka+1;
- count_open:=1;
- count_close:=0;
- buf2:=Seek_my(File_Name,close_skobka);
- while not(flag_close_end) do
- begin
- if Pos('{',buf2)<>0 then
- begin
- count_open:=count_open+1;
- end;
- if Pos('}',buf2)<>0 then
- begin
- count_close:=count_close+1;
- end;
- if count_close = count_open then
- begin
- flag_close_end:=True;
- end;
- close_skobka:=close_skobka+1;
- buf2:=Seek_my(File_Name,close_skobka);
- end;
- max:=Count_in('In_put_count.txt',open_skobka,close_skobka-1) ;
- if Result<max then result:=max;
- if name_with_skobka='do' then position:=close_skobka-1
- else position:=close_skobka-1;
- end;
- position:=position+1;
- end;
- end;
- begin
- Writeln( Count_Vlog('In_put_count.txt'));
- //Writeln(Seek_my('In_put_count.txt',2));
- //Count_in('In_put_count.txt',2,9) ;
- Readln;
- { TODO -oUser -cConsole Main : Insert code here }
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement