UVA-260 - Il Gioco dell'X

  • UVa Online Judge 解題結果請於 Submit 後,參閱 uHunt
  • 如果你有任何建議與指教,歡迎於下方留言一起討論喔!

題意概要

有兩方 (黑方與白方) 輪留在一個 的平行四邊形格中放入黑色與白色的棋子。如果黑方能建立一個由 - 行的連線,則黑方獲勝,否則由白方獲勝。白方獲勝的條件是要能建立一個由 - 的列的連線,由於此遊戲不能有平手的狀況,因此每次只能是其中一方勝出。


Input

The input is a text file containing a number of games. Each game is given by: one line containing an integer , being the number of rows. ( can he any number between and ). This line is followed by lines, each consisting of a row of characters from the set {b, w} denoting the pawns of Black and White respectively. The numbers of black and white pawns will differ by at most one. Note that all positions on the board are filled with pawns. The list of games ends with a single zero on a line of its own. (Of course, this is not a game for which a winner has to be determined.)


Output

The output will be a textfile containing one line for each game. This line should contain the number of the game (starting at ) followed by a space, and followed by an uppercase B if Black did win, or followed by an uppercase W if White did win.


Sample Input

4
bbwb
wwbw
bbwb
bwww
4
bbwb
wwbw
bwwb
wwbb
0

Sample Output

1 W
2 B
profile-image
David Lu
Hello, I'm David Lu. I am a graduate student in Department of Computer Science at National Chiao Tung University, Taiwan. I am in the Networking and Sensing Systems (NSS) Lab at NCTU. If you have any question, please feel free to contact with me.
comments powered by Disqus