JZOJ 1713. 小x的游戏(game.pas/cpp)
【9.29NOIP普及模拟】小x的游戏(game.pas/cpp)
(File IO): input:game.in output:game.out时间限制: 1000 ms 空间限制: 128000 KB 具体限制 Goto ProblemSet
简单的纯模拟,注意输入输出的格式即可
每读入一个字符,分别用几个数组记录该行该列(或者对角线,如果有的话)的该字符的个数
然后根据题意如果有一条边上有四个'X'or’O‘就输出谁赢了,否则直到最后输出平局或未结束
【total记录4*4-已经读入的以放的标记(. 除外),如果最后是还没填满棋盘,即total<>0,就是平局 ;否则就是未结束】
1 { 2 by @bobble ! 3 2017-1-19 4 } 5 program game; 6 const 7 inf='game.in'; 8 outf='game.out'; 9 10 var 11 a:array[1..4,1..4] of char; 12 hang,lie:array[1..4,1..3] of longint; 13 you,zuo:array[1..3] of longint; 14 //1=X,2=O,3=T ; you=\ zuo=/ 15 total,i,j,z,t:longint; 16 boo:Boolean; 17 18 procedure winner(apple:char); 19 begin 20 21 writeln(apple,' won'); 22 boo:=false; 23 24 end; 25 26 begin 27 assign(input,inf); 28 assign(output,outf); 29 reset(input); rewrite(output); 30 31 readln(t); 32 for i:= 1 to t do 33 begin 34 fillchar(hang,sizeof(hang),0); 35 fillchar(lie,sizeof(lie),0); 36 fillchar(zuo,sizeof(zuo),0); 37 fillchar(you,sizeof(you),0); 38 boo:=true; total:=16; 39 write('Case #',i,': '); 40 for j:= 1 to 4 do 41 begin 42 for z:= 1 to 4 do 43 begin 44 read(a[j,z]); 45 if a[j,z]<>'.' then dec(total); 46 case a[j,z] of 47 'X':begin 48 inc(hang[j,1]); 49 inc(lie[z,1]); 50 if j=z then inc(you[1]); 51 if j+z=5 then inc(zuo[1]); 52 end; 53 'O':begin 54 inc(hang[j,2]); 55 inc(lie[z,2]); 56 if j=z then inc(you[2]); 57 if j+z=5 then inc(zuo[2]); 58 end; 59 'T':begin 60 inc(hang[j,3]); 61 inc(lie[z,3]); 62 if j=z then inc(you[3]); 63 if j+z=5 then inc(zuo[3]); 64 end 65 else continue; 66 end; 67 if boo then 68 begin 69 if (hang[j,1]=4) or (lie[z,1]=4) or (you[1]=4) or (zuo[1]=4) then winner('X'); 70 if boo then 71 if (hang[j,2]=4) or (lie[z,2]=4) 72 or (you[2]=4) or (zuo[2]=4) then winner('O'); 73 if (hang[j,3]=1)and (boo) then 74 begin 75 if (hang[j,1]=3) then winner('X'); 76 if (hang[j,2]=3) then winner('O'); 77 end; 78 if (lie[z,3]=1)and (boo) then 79 begin 80 if (lie[z,1]=3) then winner('X'); 81 if (lie[z,2]=3) then winner('O'); 82 end; 83 if (you[3]=1)and (boo) then 84 begin 85 if (you[1]=3) then winner('X'); 86 if (you[2]=3) then winner('O'); 87 end; 88 if (zuo[3]=1) and (boo) then 89 begin 90 if (zuo[1]=3) then winner('X'); 91 if (zuo[2]=3) then winner('O'); 92 end; 93 end; 94 end; 95 readln; 96 end; 97 if boo then 98 if total=0 then writeln('Draw') 99 else writeln('Game has not completed'); 100 readln; 101 end; 102 103 close(input); 104 close(output); 105 end.