Parity

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
str: string;
f: char;
i, l, sum: integer;
begin
reset(input, 'parity.in');
rewrite(output, 'parity.out');
readln(str);
while str <> '#' do
begin
l:= length(str);
f:= str[l];
sum:= 0;
for i:= 1 to (l-1) do
begin
sum:= sum + StrToInt(str[i]);
end;
if f = 'o' then
begin
if (sum mod 2) = 0 then str[l]:= '1'
else str[l]:= '0';
end;
if f = 'e' then
begin
if (sum mod 2) = 0 then str[l]:= '0'
else str[l]:= '1';
end;
writeln(str);
readln(str);
end;
{ TODO -oUser -cConsole Main : Insert code here }
end.