CJCoding With Joseph
15free / daySign inCreate account

A tic-tac-toe board is an array<array<char, 3>, 3>: b[row][col] is 'X', 'O', or '.' for an empty cell.

Write a function char winner(const array<array<char, 3>, 3>& b) that returns 'X' if X has three in a line, 'O' if O has three in a line, and '-' if neither player has a line. A line is any of the 3 rows, 3 columns, or 2 diagonals. Three empty cells '.' in a line are NOT a win. Assume at most one player has a line.

The test prints the returned character on its own line. For the board X X X O O . . . .

it prints the output shown in Expected Output.

Do NOT write a main function.

Expected output

X
-
O

= newline. The output ends with a newline, so print one after the last line.

Hints4 available
Topics
STL Containersstd::array
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your output

Run your code to see the output here...

Test cases

Run your code to see test case results.