fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 3;
  5.  
  6. void outputWinner(int players[], int notComplete) {
  7. if (players[0] != players[1]) {
  8. cout << "Jucătorul ";
  9. if (players[0] > players[1]) {
  10. cout << 0;
  11. } else {
  12. cout << 1;
  13. }
  14. } else if (notComplete) {
  15. cout << "Continuă";
  16. } else {
  17. cout << "Egal";
  18. }
  19. }
  20.  
  21. void lineCheck (int players[], int firstNum, int secondNum, int thirdNum) {
  22. if (firstNum == 0 && secondNum == 0 && thirdNum == 0) {
  23. ++players[0];
  24. } else if (firstNum == 1 && secondNum == 1 && thirdNum == 1) {
  25. ++players[1];
  26. }
  27. }
  28.  
  29. int main() {
  30. int players[MAX_SIZE - 1] = {0};
  31. int matrix[MAX_SIZE][MAX_SIZE], notComplete = 0;
  32. for (int i = 0; i < MAX_SIZE; ++i) {
  33. for (int j = 0; j < MAX_SIZE; ++j) {
  34. cin >> matrix[i][j];
  35. if (j == MAX_SIZE - 1) {
  36. lineCheck(players, matrix[i][j], matrix[i][j - 1], matrix[i][j - 2]);
  37. if (i == MAX_SIZE - 1) {
  38. lineCheck(players, matrix[i][j], matrix[i - 1][j - 1], matrix[i - 2][j - 2]);
  39. }
  40. } else if (i == MAX_SIZE - 1) {
  41. lineCheck(players, matrix[i][j], matrix[i - 1][j], matrix[i - 2][j]);
  42. if (j == 0) {
  43. lineCheck(players, matrix[i][j], matrix[i - 1][j + 1], matrix[i - 2][j + 2]);
  44. }
  45. }
  46. if (matrix[i][j] == 2) {
  47. notComplete = 1;
  48. }
  49. }
  50. }
  51. outputWinner(players, notComplete);
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5268KB
stdin
1 0 1
0 1 2
1 2 0
stdout
Jucătorul 1