코딩도장

코딩도장

변경이력

돌아가기
2 40개 문자 추가

2014年12月05日 14:47

김 한길

```{.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.중간에 입력에서 잘못된 값을 받는 경우는 생각하지 않았습니다.
```{.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.중간에 입력에서 잘못된 값을 받는 경우는 생각하지 않았습니다.
1 Original

2014年12月05日 14:45

김 한길

```{.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; } ``` 검토부탁드립니다
```{.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; } ``` 검토부탁드립니다
코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.

코딩도장 © 2014 · 문의 [email protected]
피드백 · 개인정보취급방침 · RSS

AltStyle によって変換されたページ (->オリジナル) /