Skip to content

Instantly share code, notes, and snippets.

@4lex1v
Created October 2, 2012 20:04
Show Gist options
  • Save 4lex1v/3822958 to your computer and use it in GitHub Desktop.
Save 4lex1v/3822958 to your computer and use it in GitHub Desktop.
Задача 5 способ 5 + 6
{модуль}
unit LinkedList;
interface
type
pt =^ elem;
elem = record
job: string;
count: integer;
next: pt;
end;
llist = pt;
procedure put(var ll: pt; entry: string);
procedure printList(var ll: pt);
procedure count(ll: pt);
implementation
procedure put(var ll: pt; entry: string);
var p, q: pt;
begin
new(q);
q^.job := entry;
q^.count := 1;
q^.next := nil;
if ll = nil then
ll := q
else
begin
p := ll;
while p^.next <> nil do
p := p^.next;
p^.next := q;
end;
end;
procedure printList(var ll: pt);
begin
if ll <> nil then
begin
writeln(ll^.job, ' - ', ll^.count, ', ');
printList(ll^.next);
end;
end;
procedure count(ll: pt);
var
cur: pt;
function iterCount(var elem: pt; var nx: pt; acc: integer): integer;
begin
if nx = nil then
iterCount := acc
else begin
if elem^.job = nx^.job then begin
nx^.job := '';
iterCount := iterCount(elem, nx^.next, acc + 1);
end
else
iterCount := iterCount(elem, nx^.next, acc);
end;
end;
begin
if ll <> nil then begin
cur := ll;
if cur^.job <> '' then begin
ll := ll^.next;
cur^.count := iterCount(cur, ll, 1);
writeln(cur^.job, ' - ', cur^.count);
end;
count(cur^.next);
end;
end;
end.
{программа}
program var_5;
uses LinkedList;
var
file1: textfile;
list: llist;
str, tmp: string;
begin
assign(file1, 'inp.txt');
reset(file1);
repeat
readln(file1, str);
tmp := copy(str, 8, 11);
put(list, tmp);
until(EOF(file1));
printList(list);
writeln();
count(list);
close(file1);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment