Ուղարկել | Բոլոր լուծումները | Լավագույն լուծումները | Վերադառնալ ցուցակին |
COCI0018 - MARATON |
Albert, Barbara, Casper, Dinko, Eustahije are starting a marathon game of tic-tac-toe, played on an N×N board.
Initially, all squares on the board are empty and players take turns writing the first letter of their name into any of the empty squares (because the players are elite, no two players have the same first letter).
The game ends when some player places 3 of his or her letters consecutively in a row, column or diagonally. That player is declared the winner.
Write a program that, given the state of the board, determines if the game is over and who won if it is.
Input.
The first line of input contains the integer N (1 ≤ N ≤ 30), the size of the board.
The following N lines contain N characters each. The characters will be uppercase letters of the English alphabet or '.' (if the square is empty).
The input data will be such that there is at most one winner.
Output.
If the game is over, output the first letter of the winner's name. If not, output "ongoing" (even if the board is full).
Sample tests.
N |
stdin |
stdout |
1 |
3 XOC XOC X.. |
X |
2 |
4 .... ..A. AAB. .B.B |
ongoing |
Ավելացրեց. | Հրանտ Հովհաննիսյան |
Ամսաթիվ. | 2016-05-09 |
Ժամանակի սահմանափակումը. | 1s |
Ծրագրի տեքստի սահմանափակումը. | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Լեզուներ. | Բոլորը բացի ASM32 ASM64 GAWK CLPS CLOJURE D ERL FSHARP FORTRAN GOSU HASK ICON ICK JS-MONKEY NEM NIM OBJC-CLANG PICO PIKE PYPY PYPY3 PY_NBC RUST SCM guile CHICKEN SED TCL WHITESPACE |
Աղբյուրը. | COCI, Contest #6, 2006-2007 |