Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. void zawiniecie(int (&siatka)[14][22])
  4. {
  5. for (int s = 0; s != 14; s++)
  6. for (int ss = 0; ss != 22; ss++)
  7. {
  8. if (s == 0 || s == 13 || ss == 0 || ss == 21)
  9. {
  10. if (s == 0)
  11. siatka[0][ss] = siatka[12][ss];
  12. else if (s == 13)
  13. siatka[13][ss] = siatka[1][ss];
  14. else if (ss == 0)
  15. siatka[s][0] = siatka[s][20];
  16. else if (ss == 21)
  17. siatka[s][21] = siatka[s][1];
  18. }
  19. }
  20. siatka[13][21] = siatka[1][1];
  21. siatka[0][0] = siatka[12][20];
  22. siatka[13][0] = siatka[1][20];
  23. siatka[0][21] = siatka[12][1];
  24. }
  25. void pokolenia(int (&siateczka)[14][22])
  26. {
  27.  
  28. int ilosc, g1, h1, pok[14][22];
  29. for (int z = 0; z != 14; z++)
  30. for (int x = 0; x != 22; x++)
  31. pok[z][x] = siateczka[z][x];
  32. for (int g = 1; g != 14; g++)
  33. {
  34. for (int h = 1; h != 22; h++)
  35. {
  36. ilosc = 0;
  37. if (siateczka[g][h] == 1)
  38. {
  39. for (g1 = -1; g1 != 2; g1++)
  40. for (h1 = -1; h1 != 2; h1++)
  41. if (siateczka[g + g1][h + h1] == 1)
  42. ilosc++;
  43. if (ilosc == 3 || ilosc == 4)
  44. pok[g][h] = 1;
  45. else
  46. pok[g][h] = 0;
  47. }
  48. else
  49. {
  50. for (g1 = -1; g1 != 2; g1++)
  51. for (h1 = -1; h1 != 2; h1++)
  52. if (siateczka[g + g1][h + h1] == 1)
  53. ilosc++;
  54. if (ilosc == 3)
  55. pok[g][h] = 1;
  56. else
  57. pok[g][h] = 0;
  58. }
  59. }
  60. }
  61. zawiniecie(pok);
  62. for (int z = 0; z != 14; z++)
  63. for (int x = 0; x != 22; x++)
  64. siateczka[z][x] = pok[z][x];
  65. }
  66. int main()
  67. {
  68. std::ifstream dane("gra.txt");
  69. std::ofstream wynik("wynik.txt");
  70. char a;
  71. bool tosamo = true, znaleziona = false;
  72. int plansza[14][22], plansza1[14][22], zywe = 0, zywi_sas_2pok = 0, ktore_pok, zywe_tosamo = 0;
  73. for (int q = 0; q != 14; q++)
  74. for (int w = 0; w != 22; w++)
  75. {
  76. if (q == 0 || q == 13 || w == 0 || w == 21)
  77. continue;
  78. dane >> a;
  79. if (a == 'X')
  80. plansza[q][w] = 1;
  81. else
  82. plansza[q][w] = 0;
  83. }
  84. zawiniecie(plansza);
  85. for (int q = 0; q != 14; q++)
  86. for (int w = 0; w != 22; w++)
  87. plansza1[q][w] = plansza[q][w];
  88. for (int h = 0; h != 100; h++)
  89. {
  90. tosamo = true;
  91. pokolenia(plansza);
  92. if (h != 0)
  93. pokolenia(plansza1);
  94. if (znaleziona == false)
  95. for (int q = 1; q != 13; q++)
  96. for (int w = 1; w != 21; w++)
  97. if (plansza[q][w] != plansza1[q][w])
  98. tosamo = false;
  99. if (tosamo == true && znaleziona == false)
  100. {
  101. znaleziona = true;
  102. ktore_pok = h+1;
  103. for (int g3 = 1; g3 != 13; g3++)
  104. for (int h3 = 1; h3 != 21; h3++)
  105. if (plansza[g3][h3] == 1)
  106. zywe_tosamo++;
  107. }
  108. if (h == 35)
  109. for (int g1 = -1; g1 != 2; g1++)
  110. for (int h1 = -1; h1 != 2; h1++)
  111. {
  112. if (g1 == 0 && h1 == 0)
  113. continue;
  114. if (plansza[2 + g1][19 + h1] == 1)
  115. zywi_sas_2pok++;
  116. }
  117. if (h == 0)
  118. for (int g2 = 1; g2 != 13; g2++)
  119. for (int h2 = 1; h2 != 21; h2++)
  120. if (plansza[g2][h2] == 1)
  121. zywe++;
  122. }
  123. std::cout << zywe << std::endl << zywi_sas_2pok << std::endl << ktore_pok << " " << zywe_tosamo;
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement