ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1195. Ouths and Crosses

WA #9
I checked all tests from webboard and my own tests - no any errors...

It's my code:

program krestiki;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var  a,b,c:integer;
s:array[1..8] of string;
cr,ou,be,dop,nul:boolean;
ouc:integer;
begin

ReadLn (s[1]);
ReadLn (s[2]);
ReadLn (s[3]);

//Creation of game lines
s[4]:=s[1][1]+s[2][1]+s[3][1];
s[5]:=s[1][2]+s[2][2]+s[3][2];
s[6]:=s[1][3]+s[2][3]+s[3][3];
s[7]:=s[1][1]+s[2][2]+s[3][3];
s[8]:=s[1][3]+s[2][2]+s[3][1];


//Check for winning ouths or crosses in first two moves
for a:=1 to 8 do
begin
if (pos('XX#',s[a])<>0) or (pos('X#X',s[a])<>0) or (pos('#XX',s[a])<>0) or (pos('XXX',s[a])<>0) then
cr:=true else
if (pos('OO#',s[a])<>0) or (pos('O#O',s[a])<>0) or (pos('#OO',s[a])<>0) or (pos('OOO',s[a])<>0)  then
begin

//Check for two winning lines for ouths
if nul=true then
ou:=true;
nul:=true;
end;
end;

nul:=false;

//Check for every second move by crosses
if (cr=false) and (ou=false) then

for c:=1 to 3 do
for b:=1 to 3 do
if s[c][b]='#' then
begin
s[c][b]:='X'; be:=true;
s[4]:=s[1][1]+s[2][1]+s[3][1];
s[5]:=s[1][2]+s[2][2]+s[3][2];
s[6]:=s[1][3]+s[2][3]+s[3][3];
s[7]:=s[1][1]+s[2][2]+s[3][3];
s[8]:=s[1][3]+s[2][2]+s[3][1];
for a:=1 to 8 do
begin
if (pos('XX#',s[a])<>0) or (pos('X#X',s[a])<>0) or (pos('#XX',s[a])<>0) or (pos('XXX',s[a])<>0) then
begin

//Check for two winning lines for crosses
if nul=true then
cr:=true;
nul:=true;
end;

if be=true then
s[c][b]:='#';

be:=false;
end;
end;

if cr=true the WriteLn ('Crosses win') else
if ou=true then WriteLn ('Ouths win') else
WriteLn ('Draw');
ReadLn;
end.