← Back to STL Containers
Question 547
Tic-Tac-Toe Winner
Tic-Tac-Toe Winner
A tic-tac-toe board is anarray<array<char, 3>, 3>:b[row][col]is'X','O', or'.'for an empty cell. Write a functionchar 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 — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
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.