```{.cpp}
#include <iostream>
using namespace std;
int main()
{
int pb[9] = {0};
int input = 0;
int turn = 0;
int end = 1;
int e;
while (end!=0)
{
e = 1;
int c=1;
if (turn == 1) turn = 2;
else turn=1;
while (e)
{
cout << "player" << turn << "- ";
cin >> input;
cin.get();
if (pb[input - 1]) continue;
e = 0;
if (turn == 1) pb[input - 1] = 1;
else pb[input - 1] = -1;
}
for (int i = 0; i < 3; i++) if ((pb[i] + pb[i + 1] + pb[i + 2]) == 3 || (pb[i] + pb[i + 1] + pb[i + 2]) == -3) end=0;
for (int i = 0; i < 3; i++) if ((pb[i] + pb[i + (1* 3)] + pb[i+(2 *3)]) == 3 || (pb[i] + pb[i+(1* 3)] + pb[i+(2 *3)] ==3 )) end = 0;
if ((pb[0] + pb[4] + pb[8]) == -3 || (pb[0] + pb[4] + pb[8])==3) end = 0;
if ((pb[2] + pb[4] + pb[6]) == -3 || (pb[2] + pb[4] + pb[6])==3) end = 0;
c++;
if (c == 9) break;
}
for (int i = 0; i < 9; i++)
{
if (i % 3 == 0) cout << endl;
if (pb[i] == 1) cout <<"O ";
else if (pb[i] == -1) cout << "X ";
else cout << i+1<<" ";
}
cout << endl <<"win players is " << turn<<endl;
cin.get();
cin.get();
return 0;
}
```
검토부탁드립니다.
ps.중간에 입력에서 잘못된 값을 받는 경우는 생각하지 않았습니다.
```{.cpp}
#include <iostream>
using namespace std;
int main()
{
int pb[9] = {0};
int input = 0;
int turn = 0;
int end = 1;
int e;
while (end!=0)
{
e = 1;
int c=1;
if (turn == 1) turn = 2;
else turn=1;
while (e)
{
cout << "player" << turn << "- ";
cin >> input;
cin.get();
if (pb[input - 1]) continue;
e = 0;
if (turn == 1) pb[input - 1] = 1;
else pb[input - 1] = -1;
}
for (int i = 0; i < 3; i++) if ((pb[i] + pb[i + 1] + pb[i + 2]) == 3 || (pb[i] + pb[i + 1] + pb[i + 2]) == -3) end=0;
for (int i = 0; i < 3; i++) if ((pb[i] + pb[i + (1* 3)] + pb[i+(2 *3)]) == 3 || (pb[i] + pb[i+(1* 3)] + pb[i+(2 *3)] ==3 )) end = 0;
if ((pb[0] + pb[4] + pb[8]) == -3 || (pb[0] + pb[4] + pb[8])==3) end = 0;
if ((pb[2] + pb[4] + pb[6]) == -3 || (pb[2] + pb[4] + pb[6])==3) end = 0;
c++;
if (c == 9) break;
}
for (int i = 0; i < 9; i++)
{
if (i % 3 == 0) cout << endl;
if (pb[i] == 1) cout <<"O ";
else if (pb[i] == -1) cout << "X ";
else cout << i+1<<" ";
}
cout << endl <<"win players is " << turn<<endl;
cin.get();
cin.get();
return 0;
}
```
검토부탁드립니다.
ps.중간에 입력에서 잘못된 값을 받는 경우는 생각하지 않았습니다.