Help us understand the problem. What is going on with this article?

# 「どう書く」をこう書いてみた

More than 5 years have passed since last update.

コードにするのに30分ぐらいでした。が、昨夜のうちに問題をちらっと見てしまっていたので考えてた時間は結構長いです。

お題はこちらです。
http://nabetani.sakura.ne.jp/hena/1/

…。
ちょっとミスってたのでコソっと修正。

```#include <iostream>
#include <string>

enum Result { FAUL_X_WON, FAUL_O_WON, O_WON, X_WON, DRAW_GAME };

Result doukaku(const std::string& t)
{
int board[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for(int i = 0; i < 9; ++i)
{
if(board[t[i] - '0' - 1] != 0)
{
return static_cast<Result>(i % 2);
}
board[t[i] - '0' - 1] = i % 2 + 1;
if( (board[0] & board[1] & board[2]) ||
(board[3] & board[4] & board[5]) ||
(board[6] & board[7] & board[8]) ||
(board[0] & board[3] & board[6]) ||
(board[1] & board[4] & board[7]) ||
(board[2] & board[5] & board[8]) ||
(board[0] & board[4] & board[8]) ||
(board[2] & board[4] & board[6]))
{
return static_cast<Result>((i % 2) + 2);
}
}
return DRAW_GAME;
}

int main(int, char* [])
{
std::string s;
while((std::cin >> s).good())
{
switch(doukaku(s))
{
case FAUL_X_WON: std::cout << "Faul: x won.\n"; break;
case FAUL_O_WON: std::cout << "Faul: o won.\n"; break;
case X_WON:      std::cout << "x won.\n";       break;
case O_WON:      std::cout << "o won.\n";       break;
default:         std::cout << "Draw game.\n";   break;
}
}

return 0;
}
```
ソフトウェアエンジニア、言語オタク
http://d.hatena.ne.jp/E_Mattsan/
We build applications which work well and make customers happy.
http://www.esm.co.jp
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away