fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. char arr[3][3];
  7. for (int i = 0; i < 3; i++) {
  8. for (int j = 0; j < 3; j++) {
  9. cin >> arr[i][j];
  10. }
  11. }
  12. bool foundWinner = false;
  13. for (int i = 0; i < 3; i++) {
  14. char x = arr[i][0];
  15. int cnt = 0;
  16. for (int j = 0; j < 3; j++) {
  17. if (x == arr[i][j]) cnt++;
  18. else break;
  19. }
  20. if (cnt == 3 && x != '.' && !foundWinner) {
  21. cout << x << " wins\n";
  22. foundWinner = true;
  23. }
  24. }
  25. if (!foundWinner) {
  26. for (int i = 0; i < 3; i++) {
  27. char x = arr[0][i];
  28. int cnt = 0;
  29. for (int j = 0; j < 3; j++) {
  30. if (x == arr[j][i]) cnt++;
  31. else break;
  32. }
  33. if (cnt == 3 && x != '.' && !foundWinner) {
  34. cout << x << " wins\n";
  35. foundWinner = true;
  36. }
  37. }
  38. }
  39. char x = arr[1][1];
  40. int cnt1 = 0, cnt2 = 0;
  41. for (int i = 0; i < 3; i++) {
  42. if (arr[i][i] == x && arr[i][i] != '.') cnt1++;
  43. if (arr[i][2 - i] == x && arr[i][2 - i] != '.') cnt2++;
  44. }
  45. if (cnt1 == 3 || cnt2 == 3) {
  46. cout << x << " wins\n";
  47. foundWinner = true;
  48. }
  49. if (!foundWinner)
  50. cout << "draw\n";
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 4304KB
stdin
X O X
X O O
X X O
stdout
X wins