In order to generate that ugly list, I organised the entries and the votes into two separate text files.
Code: Select all
drc 11, 15, 8, 16
dvgrn 13, 8, 5, 3, 2.
biggiemac 13, 15, 14, 3, 16, 8, 1, 2
Scorbie 14, 13, 15, 17, 3, 9, 10, 4, 1, 16, 7, 5, 2
A for awesome 13, 7, 1, 15, 5, 11, 16
calcyman 15, 13, 4, 17, 16, 3
Saka 8, 14, 6, 3, 2
Kiran 15,6,8,14,4,10,13,3,5,2,12,11
gameoflifeboy 3, 17, 14, 12, 15, 2
isaacg 13, 15, 14
codeholic 15,13,14
Extrementhusiast (13, 14, 15), (16, 5, 11), (9, 6, 8, 17), (1, 7, 10), (3, 12), (4, 2).
AwesomeFace 15, 13, 12, 4, 8
mniemiec 16, 14, 9
Sokwe 16, 13, 8, 14, 5, 4, 15, 6, 9, 11
wildmyron 14, 13, 15, 3, 16.
chris_c 13, 15, 16
simeks 13, 14, 1, 3, 15, 11, 9, 16, 2, 12, 4
Kazyan 7, 9, 14, 13, 15, 17, 16, 4
muzik 15, 6
triller 15
Alexey_Nigin 15, 16, 14, 13, 6, 3, 8, 2, 4
Code: Select all
// No parameters are hardcoded, so this program can be used for
// any competition with the same voting system. The inputs are
// contained within "Entries.in" and "Votes.in". These two
// files and the program should reside in the same folder.
program Judge;
{$APPTYPE CONSOLE}
uses
SysUtils, Classes;
var
Entries,Votes,Outcome : TStringList; // Some array indices start from
i,T1,T2 : Integer; // zero, some from one, hence
A : array of array [1..2] of Integer; // the confusion. For more
RepThis : Boolean; // info on the topic, see
// https://xkcd.com/163/
procedure Canonize(var S : String);
var
i : Integer;
begin
for i:=1 to Length(S) do
if not CharInSet(S[i],['0','1','2','3','4','5','6','7','8','9']) then
S[i]:='.';
for i:=Length(S)-1 downto 1 do
if (S[i] + S[i+1]) = '..' then
Delete(S,i,1);
if S[1] <> '.' then
S:='.' + S;
if S[Length(S)] = '.' then
Delete(S,Length(S),1);
end;
procedure AddVote(S : String);
var
i,Sum : Integer;
begin
Canonize(S);
Sum:=0;
for i:=Length(S) downto 1 do
if S[i] = '.' then
begin
Inc(Sum);
Inc(A[StrToInt(Copy(S,i+1,Length(S)-i))-1,2],Sum);
Delete(S,i,Length(S)-i+1);
end;
end;
begin
try
{ TODO -oUser -cConsole Main : Insert code here }
Entries:=TStringList.Create;
Entries.LoadFromFile('Entries.in');
Votes:=TStringList.Create;
Votes.LoadFromFile('Votes.in');
SetLength(A,Entries.Count);
for i:=0 to High(A) do
begin
A[i,1]:=i+1;
A[i,2]:=0;
end;
for i:=0 to Votes.Count-1 do
AddVote(Votes[i]);
repeat // Bubbles are cool!
RepThis:=False;
for i:=0 to High(A)-1 do
if A[i,2] < A[i+1,2] then
begin
T1:=A[i,1];
T2:=A[i,2];
A[i,1]:=A[i+1,1];
A[i,2]:=A[i+1,2];
A[i+1,1]:=T1;
A[i+1,2]:=T2;
RepThis:=True;
end;
until not RepThis;
Outcome:=TStringList.Create;
for i:=0 to High(A) do
Outcome.Add('[size=' + IntToStr(((High(A)-i)*100) div High(A) + 100) +
']' + IntToStr(i+1) + '. ' + Trim(Entries[A[i,1]-1]) + ' [i](' +
IntToStr(A[i,2]) + ' points)[/i][/size]');
Outcome.SaveToFile('Outcome.out');
WriteLn('Everything is OK.');
ReadLn;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
This is all I have for now. I will hopefully answer your questions tomorrow.