Created
April 15, 2013 13:05
-
-
Save soimort/5387914 to your computer and use it in GitHub Desktop.
GCJ 2013 Qualification Round - Problem A
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
-- Authored by tanakh | |
{-# LANGUAGE TupleSections #-} | |
import Control.Applicative | |
import Control.Monad | |
import Data.List | |
import Text.Printf | |
main :: IO () | |
main = do | |
n <- readLn | |
forM_ [1..n] $ \cn -> do | |
bd <- replicateM 4 getLine | |
_ <- getLine | |
let check c = any (all (\(i, j) -> is $ bd !! i !! j)) ps where | |
is d = d == c || d == 'T' | |
ps = [ [ (i, j) | j <- [0..3]] | i <- [0..3] ] ++ | |
[ [ (j, i) | j <- [0..3]] | i <- [0..3] ] ++ | |
[ map (\i -> (i, i)) [0..3] ] ++ | |
[ map (\i -> (i, 3-i)) [0..3] ] | |
let ans = case () of | |
_ | check 'X' -> "X won" | |
| check 'O' -> "O won" | |
| any (any (== '.')) bd -> "Game has not completed" | |
| otherwise -> "Draw" | |
printf "Case #%d: %s\n" (cn :: Int) ans |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment