Skip to content

Instantly share code, notes, and snippets.

@4lex1v
Created September 28, 2012 21:23
Show Gist options
  • Save 4lex1v/3802146 to your computer and use it in GitHub Desktop.
Save 4lex1v/3802146 to your computer and use it in GitHub Desktop.
Задача 5 способ 3
program prog;
type
job_entry = record
job: string;
count: integer;
end;
table = array[1..15] of job_entry;
var
jobs: table;
tmp: string;
i, current: byte;
index: integer;
procedure addEntry(var entry: job_entry; str: string);
begin
entry.job := str;
entry.count := entry.count + 1;
end;
function readNextEntry(): string;
var
tmp: string;
begin
readln(tmp);
readNextEntry := copy(tmp, 8, 11);
end;
function contains(t: table; entry: string): integer;
var
j: byte;
found: integer;
begin
found := -1;
for j:=1 to 16 do
if t[j].job = entry then
found := j;
contains := found;
end;
begin
assign(input, 'inp.txt');
reset(input);
assign(output, 'out.txt');
rewrite(output);
for i:=1 to 15 do
begin
readln(tmp);
writeln(tmp);
end;
reset(input);
for i:=1 to 15 do
begin
jobs[i].job := 'job_entry';
jobs[i].count := 0;
end;
current := 1;
for i:=1 to 15 do
begin
tmp := readNextEntry();
index := contains(jobs, tmp);
if index = -1 then
begin
addEntry(jobs[current], tmp);
current := current + 1;
end
else
jobs[index].count := jobs[index].count + 1
end;
for i:=1 to current-1 do
writeln(jobs[i].job, ' - ', jobs[i].count);
close(input);
close(output);
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment