Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- void zawiniecie(int (&siatka)[14][22])
- {
- for (int s = 0; s != 14; s++)
- for (int ss = 0; ss != 22; ss++)
- {
- if (s == 0 || s == 13 || ss == 0 || ss == 21)
- {
- if (s == 0)
- siatka[0][ss] = siatka[12][ss];
- else if (s == 13)
- siatka[13][ss] = siatka[1][ss];
- else if (ss == 0)
- siatka[s][0] = siatka[s][20];
- else if (ss == 21)
- siatka[s][21] = siatka[s][1];
- }
- }
- siatka[13][21] = siatka[1][1];
- siatka[0][0] = siatka[12][20];
- siatka[13][0] = siatka[1][20];
- siatka[0][21] = siatka[12][1];
- }
- void pokolenia(int (&siateczka)[14][22])
- {
- int ilosc, g1, h1, pok[14][22];
- for (int z = 0; z != 14; z++)
- for (int x = 0; x != 22; x++)
- pok[z][x] = siateczka[z][x];
- for (int g = 1; g != 14; g++)
- {
- for (int h = 1; h != 22; h++)
- {
- ilosc = 0;
- if (siateczka[g][h] == 1)
- {
- for (g1 = -1; g1 != 2; g1++)
- for (h1 = -1; h1 != 2; h1++)
- if (siateczka[g + g1][h + h1] == 1)
- ilosc++;
- if (ilosc == 3 || ilosc == 4)
- pok[g][h] = 1;
- else
- pok[g][h] = 0;
- }
- else
- {
- for (g1 = -1; g1 != 2; g1++)
- for (h1 = -1; h1 != 2; h1++)
- if (siateczka[g + g1][h + h1] == 1)
- ilosc++;
- if (ilosc == 3)
- pok[g][h] = 1;
- else
- pok[g][h] = 0;
- }
- }
- }
- zawiniecie(pok);
- for (int z = 0; z != 14; z++)
- for (int x = 0; x != 22; x++)
- siateczka[z][x] = pok[z][x];
- }
- int main()
- {
- std::ifstream dane("gra.txt");
- std::ofstream wynik("wynik.txt");
- char a;
- bool tosamo = true, znaleziona = false;
- int plansza[14][22], plansza1[14][22], zywe = 0, zywi_sas_2pok = 0, ktore_pok, zywe_tosamo = 0;
- for (int q = 0; q != 14; q++)
- for (int w = 0; w != 22; w++)
- {
- if (q == 0 || q == 13 || w == 0 || w == 21)
- continue;
- dane >> a;
- if (a == 'X')
- plansza[q][w] = 1;
- else
- plansza[q][w] = 0;
- }
- zawiniecie(plansza);
- for (int q = 0; q != 14; q++)
- for (int w = 0; w != 22; w++)
- plansza1[q][w] = plansza[q][w];
- for (int h = 0; h != 100; h++)
- {
- tosamo = true;
- pokolenia(plansza);
- if (h != 0)
- pokolenia(plansza1);
- if (znaleziona == false)
- for (int q = 1; q != 13; q++)
- for (int w = 1; w != 21; w++)
- if (plansza[q][w] != plansza1[q][w])
- tosamo = false;
- if (tosamo == true && znaleziona == false)
- {
- znaleziona = true;
- ktore_pok = h+1;
- for (int g3 = 1; g3 != 13; g3++)
- for (int h3 = 1; h3 != 21; h3++)
- if (plansza[g3][h3] == 1)
- zywe_tosamo++;
- }
- if (h == 35)
- for (int g1 = -1; g1 != 2; g1++)
- for (int h1 = -1; h1 != 2; h1++)
- {
- if (g1 == 0 && h1 == 0)
- continue;
- if (plansza[2 + g1][19 + h1] == 1)
- zywi_sas_2pok++;
- }
- if (h == 0)
- for (int g2 = 1; g2 != 13; g2++)
- for (int h2 = 1; h2 != 21; h2++)
- if (plansza[g2][h2] == 1)
- zywe++;
- }
- std::cout << zywe << std::endl << zywi_sas_2pok << std::endl << ktore_pok << " " << zywe_tosamo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement