| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- const
- name_len = 11;
- phone_len = 9;
- type
- TPE = record
- Name : string[name_len];
- Phone : string[phone_len];
- end;
- TPEa = array [1..20] of TPE;
- Procedure Exchange(var a,b:TPE);
- var
- t:tpe;
- begin
- t:=a;a:=b;b:=t;
- end;{Exchange}
- {----------------------------------------}
- Procedure QSort(var aA:TPEa;L,R:word);
- var
- i,j : word;
- cen : string[phone_len];
- begin
- if L<>R then
- begin
- cen:=aA[(l+r) div 2].Phone;
- i:=l;
- j:=r;
- while i<=j do
- begin
- while (i<r) and (aa[i].Phone > cen) do inc(i);
- while (j>l) and (aa[j].Phone < cen) do dec(j);
- if i<=j then
- begin
- Exchange(aA[i],aA[j]);
- Inc(i);
- Dec(j);
- end;
- end;
- if j > L then QSort(Aa,L,j);
- if i < r then QSort(aA,i,r);
- end;
- end;{SortNum}
- {----------------------------------------}
- var
- Ar : TPEa;
- INP : text;
- i,cnt : integer;
- begin
- Assign(INP,'phones.txt');
- Assign(Output,'out6.txt');
- Rewrite(Output);
- {$I-}
- Reset(INP);
- If IOResult <> 0 then
- begin
- WriteLn('File ''phones.txt'' not found');
- Halt(255);
- end;
- {$I+}
- cnt:=1;
- While not EOF(INP) do
- begin
- Read(INP,Ar[cnt].Name);
- ReadLn(INP,Ar[cnt].Phone);
- WriteLn(Ar[cnt].Name,Ar[cnt].Phone);
- inc(cnt);
- end;
- Close(INP);
- WriteLn('Result:');
- Dec(cnt);
- QSort(Ar,1,cnt);
- for i := 1 to cnt do WriteLn(Ar[i].Name,Ar[i].Phone);
- WriteLn('End.');
- end.
|