Created
September 28, 2012 21:24
-
-
Save 4lex1v/3802151 to your computer and use it in GitHub Desktop.
Задача 5 способ 4 + Модуль
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{Модуль} | |
unit myUnit; | |
interface | |
type | |
job_entry = record | |
job: string; | |
count: integer; | |
end; | |
table = array[1..16] of job_entry; | |
procedure addEntry(var entry: job_entry; str: string); | |
function readNextEntry(): string; | |
function contains(t: table; entry: string): integer; | |
implementation | |
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; | |
end. | |
{Программа} | |
program prog; | |
uses MyUnit; | |
var | |
jobs: table; | |
tmp: string; | |
i, current, index: byte; | |
begin | |
assign(input, 'inp.txt'); | |
reset(input); | |
assign(output, 'out.txt'); | |
rewrite(output); | |
for i:=1 to 16 do | |
begin | |
jobs[i].job := 'job_entry'; | |
jobs[i].count := 0; | |
end; | |
current := 1; | |
for i:=1 to 16 do | |
begin | |
tmp := readNextEntry(); | |
index := contains(jobs, tmp); | |
if index = 255 then | |
begin | |
addEntry(jobs[current], tmp); | |
current := current + 1; | |
end | |
else | |
jobs[index].count := jobs[index].count + 1 | |
end; | |
for i:=1 to current-2 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