fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool h_1(int arrayfic[3][3])
  5. {
  6. return (arrayfic[0][0]==arrayfic[0][1])&&(arrayfic[0][0]==arrayfic[0][2]);
  7. }
  8.  
  9. bool h_2(int arrayfic[3][3])
  10. {
  11. return (arrayfic[1][0]==arrayfic[1][1])&&(arrayfic[1][0]==arrayfic[1][2]);
  12. }
  13.  
  14. bool h_3(int arrayfic[3][3])
  15. {
  16. return (arrayfic[2][0]==arrayfic[2][1])&&(arrayfic[2][0]==arrayfic[2][2]);
  17. }
  18.  
  19. bool v_1(int arrayfic[3][3])
  20. {
  21. return (arrayfic[0][0]==arrayfic[1][0])&&(arrayfic[0][0]==arrayfic[2][0]);
  22. }
  23. bool v_2(int arrayfic[3][3])
  24. {
  25. return (arrayfic[0][1]==arrayfic[1][1])&&(arrayfic[0][1]==arrayfic[2][1]);
  26. }
  27. bool v_3(int arrayfic[3][3])
  28. {
  29. return (arrayfic[0][2]==arrayfic[1][2])&&(arrayfic[0][2]==arrayfic[2][2]);
  30. }
  31.  
  32. bool lt_br(int arrayfic[3][3])
  33. {
  34. return (arrayfic[0][0]==arrayfic[1][1])&&(arrayfic[0][0]==arrayfic[2][2]);
  35. }
  36.  
  37. bool lb_tr(int arrayfic[3][3])
  38. {
  39. return (arrayfic[0][2]==arrayfic[1][1])&&(arrayfic[0][2]==arrayfic[2][0]);
  40. }
  41.  
  42.  
  43. bool win(int arrayfic[3][3]){
  44. int count1 = 0, count2 = 0;
  45. bool player1 = false;
  46.  
  47. for(int i=0; i<3; ++i)
  48. for(int j=0; j<3; ++j)
  49. (arrayfic[i][j]==1)?++count1:++count2;
  50. count1<=count2?player1=true:player1=false;
  51.  
  52. for(int i=0; i<3; ++i)
  53. {
  54. for(int j=0; j<3; ++j)
  55. {
  56. if(!arrayfic[i][j])
  57. {
  58. arrayfic[i][j] = player1?1:2;
  59. if(i==0&&j==0){ if(h_1(arrayfic)||v_1(arrayfic)||lt_br(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  60. if(i==0&&j==1){ if(h_1(arrayfic)||v_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  61. if(i==0&&j==2){ if(h_1(arrayfic)||v_3(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  62. if(i==1&&j==0){ if(v_1(arrayfic)||h_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  63. if(i==1&&j==1){ if(h_2(arrayfic)||v_2(arrayfic)||lt_br(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  64. if(i==1&&j==2){ if(h_2(arrayfic)||v_3(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  65. if(i==2&&j==0){ if(v_1(arrayfic)||h_3(arrayfic)||lb_tr(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  66. if(i==2&&j==1){ if(h_3(arrayfic)||v_2(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  67. if(i==2&&j==2){ if(h_3(arrayfic)||v_3(arrayfic)||lt_br(arrayfic))return true; arrayfic[i][j] = 0;continue;}
  68.  
  69. }
  70. }
  71. }
  72.  
  73. return false;
  74. }
  75.  
  76. int main () {
  77. int arrayfic1[3][3]={{2,1,1},{2,0,0},{0,1,0}};
  78. int arrayfic2[3][3]={{1,0,2},{0,2,0},{0,0,1}};
  79. int arrayfic3[3][3]={{2,1,1},{2,0,0},{0,0,0}};
  80. if(win(arrayfic1))
  81. cout <<"YES"<<endl;
  82. else
  83. cout<<"NO"<<endl;
  84. if(win(arrayfic2))
  85. cout <<"YES"<<endl;
  86. else
  87. cout<<"NO"<<endl;
  88. if(win(arrayfic3))
  89. cout <<"YES"<<endl;
  90. else
  91. cout<<"NO"<<endl;
  92. return 0;
  93. }
Success #stdin #stdout 0.02s 2728KB
stdin
Standard input is empty
stdout
YES
NO
NO