
Thanks in advance
Keep posting!!!

Moderator: Board moderators
Code: Select all
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
using namespace std;
#define show(x) cout << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; i ++)
int main() {
#ifndef ONLINE_JUDGE
freopen("PopulationExplosion.in", "r", stdin);
#endif
char buf[100];
int t;
cin >> t;
int tt = 0;
while(t --) {
//show(tt);
if(tt ++)
cout << endl;
int y;
cin >> y;
cin.getline(buf, 100);
char b[20][20];
FOR(i, 20)
FOR(j, 20)
b[i][j] = ' ';
while(cin.getline(buf, 100), buf[0]) {
string line = buf;
istringstream iss(line);
//show(line);
int r, c;
iss >> r >> c;
b[r-1][c-1] = 'o';
}
FOR(k, y) {
cout << "*******************" << endl;
char next[20][20];
FOR(i, 20)
FOR(j, 20)
next[i][j] = ' ';
FOR(i, 20) {
FOR(j, 20)
cout << b[i][j];
cout << endl;
}
FOR(i, 20) {
FOR(j, 20) {
int nb = 0;
for(int ii = i-1; ii <= i+1; ii ++)
for(int jj = j-1; jj <= j+1; jj ++) {
if(!(ii == i && jj == j) && ii >= 0 && ii < 20 && jj >= 0 && jj < 20 && b[ii][jj] == 'o')
nb ++;
}
if(b[i][j] == ' ' && nb == 3)
next[i][j] = 'o';
else if(b[i][j] == 'o' && (nb < 2 || nb > 3))
next[i][j] = ' ';
else
next[i][j] = b[i][j];
}
}
FOR(i, 20)
FOR(j, 20)
b[i][j] = next[i][j];
}
cout << "*******************" << endl;
}
return 0;
}
Hey, be careful the day it gives might be 0, which should only print a line contains 20 '*'.Ghust_omega wrote:Thanks !!! Minilek this i/o was very useful , with this i see where is wrong, and I got AC, but P.E.my I/O is almost the same as yours only for one '\n' and i dont figure out how can avoid the P.E. please someone that helps
Thanks in advance
Keep posting!!!
Code: Select all
Cut after AC
Because if there are many threads for a single problem, it would be harder to find useful information from the threads. See the threads in volume 1. There are 31 pages, did you ever check page 31? why?All about problems in Volume I. If there is a thread about your problem, please use it. If not, create one with its number in the subject.