Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- int size,numberOfIteration;
- int count;
- int iteration,row,column;
- int index;
- scanf("%d",&size);
- scanf("%d",&numberOfIteration);
- char tab1[size][size];
- char tab2[size][size];
- /*for(index = 0; index < size; index++)
- {
- scanf("%s",tab1[index]);
- }*/
- for( row = 0; row < size; row++)
- {
- for( column = 0; column < size; column++)
- {
- scanf("%c",tab1[row][column]);
- }
- }
- printf("\n");
- for( iteration = 0; iteration < numberOfIteration; iteration++)
- {
- for( row = 0; row < size; row++)
- {
- for( column = 0; column < size; column++)
- {
- count = 0;
- if(tab1[row-1][column-1] == '*' && row>0 && column>0 )
- {
- count++;
- }
- if(tab1[row-1][column] == '*'&&row>0)
- {
- count++;
- }
- if(tab1[row-1][column+1] == '*'&& row>0&&column+1<size)
- {
- count++;
- }
- if(tab1[row][column-1] == '*'&&column>0)
- {
- count++;
- }
- if(tab1[row][column+1] == '*'&&column+1<size)
- {
- count++;
- }
- if(tab1[row+1][column-1] == '*'&&row+1<size)
- {
- count++;
- }
- if(tab1[row+1][column] == '*'&&row+1<size)
- {
- count++;
- }
- if(tab1[row+1][column+1] == '*'&&row+1<size&&column+1<size)
- {
- count++;
- }
- if(tab1[row][column] == '*')
- {
- if(count == 2||count == 3)
- tab2[row][column] = '*';
- else
- tab2[row][column] = '.';
- }
- else
- {
- if(count == 3)
- tab2[row][column] = '*';
- else
- tab2[row][column] = '.';
- }
- }
- }
- int temp = sizeof(char)*(size+1);
- for(index=0; index<size; ++index)
- {
- strncpy(tab1[index],tab2[index],temp);
- }
- }
- for( row = 0; row < size; row++)
- {
- for( column = 0; column < size; column++)
- {
- printf("%c",tab1[row][column]);
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement