Facebook
From yoben, 3 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 127
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Colony
  7. {
  8.         public static void main(String[] args) {
  9.             Scanner sc = new Scanner(System.in);
  10.             int arr[] = new int[8];
  11.             for(int i=0;i<8;i++){
  12.                 arr[i]=sc.nextInt();
  13.             }
  14.             int k = sc.nextInt();
  15.         cellComplete(arr, k);
  16.     }
  17.     private static void cellComplete(int[] cell, int day) {
  18.         int newCell[] = new int[8];
  19.         for (int d = 0; d < day; d++) {
  20.             for (int i = 0; i < cell.length; i++) {
  21.                 newCell[i] = cell[i];
  22.             }
  23.             if (newCell[1] == 1) {
  24.                 cell[0] = 1;
  25.             } else {
  26.                 cell[0] = 0;
  27.             }
  28.             for (int j = 1; j <= 6; j++) {
  29.                 cell[j] = newCell[j-1] ^ newCell[j + 1];
  30.             }
  31.             if(newCell[6]==1){
  32.                 cell[7]=1;
  33.             }else {
  34.                 cell[7]=0;
  35.             }
  36.         }
  37.         Arrays.stream(cell).forEach(s-> System.out.print(s+" "));
  38.     }
  39. }