#include void vypis(int field[20][20], int wolves[20][20], int sheep[20][20], int height, int width) { for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(wolves[r][c] > 0) putc('W', stdout); else if(sheep[r][c] > 0) putc('S', stdout); else if(field[r][c] == 0) putc('#', stdout); else if(field[r][c] > 0) /*printf("%d", field[r][c]);*/putc('.', stdout); else putc('*', stdout); } putc('\n', stdout); } } int main() { int width, height, turns; int field[20][20]; // 0 grass, <0 carcass, >0 soil that will grow grass in turns int sheep[20][20]; int wolves[20][20]; char str[100]; memset(sheep, 0, sizeof(sheep)); memset(wolves, 0, sizeof(wolves)); for(int r = 0; r < 20; r++) for(int c = 0; c < 20; c++) field[r][c] = 3; scanf("%d%d%d\n", &turns, &height, &width); //getchar(); for(int r = 0; r < height; r++) { fgets(str, 100, stdin); for(int c = 0; c < width; c++) { if(str[c] == 'W') wolves[r][c] = 10; else if(str[c] == 'S') sheep[r][c] = 5; // all other are soil } } for(int t = 0; t < turns; t++) { // move sheep for(int c = 0; c < width; c++) { int last = sheep[height-1][c]; for(int r = height - 1; r > 0; r--) sheep[r][c] = sheep[r-1][c]; sheep[0][c] = last; } // move wolves for(int r = 0; r < height; r++) { int last = wolves[r][width - 1]; for(int c = width - 1; c > 0; c--) wolves[r][c] = wolves[r][c-1]; wolves[r][0] = last; } // collisions - wolves eat for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(wolves[r][c] > 0 && sheep[r][c] > 0) { sheep[r][c] = 0; field[r][c] = -1; wolves[r][c] = 11; } } } // sheep eat for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(sheep[r][c] > 0 && field[r][c] == 0) { field[r][c] = 4; sheep[r][c] = 6; } } } // death of wolves for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(wolves[r][c] > 0) { wolves[r][c]--; if(wolves[r][c] == 0) field[r][c] = -1; } } } // death of sheep for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(sheep[r][c] > 0) { sheep[r][c]--; if(sheep[r][c] == 0) field[r][c] = -1; } } } // growing grass for(int r = 0; r < height; r++) { for(int c = 0; c < width; c++) { if(field[r][c] > 0) field[r][c]--; } } //printf("After turn %d\n", t); //vypis(field, wolves, sheep, height, width); } vypis(field, wolves, sheep, height, width); return 0; }