回复:(爱以走远)john horton conway 发明的一种lif...
没有按题意,随便做着玩下,因无限变化,下面死循环
[CODE]#include <iostream>
#include <iomanip>
using namespace std;
void check(int (*a)[20]);
void show(int (*a)[20]);
int main()
{
int a[12][20] = { {0,1,0,1,1,1,0},{0,0,1,0,1,0,0,0,0},{0,1,0,1,1,1,0},{0,0,1,1,1,0,0,0,0},
{0,0,1,1,1,0,0},{0,0,1,0,1,0,0,0,0},{0,1,1,1,1,1,0},{0,0,0,1,1,0,0,0,0},{},{0,0,0,0,0,0,0,0,1,1,1}};
show(a);
getchar();
while (1)
{
check(a);
show(a);
getchar();
}
return 0;
}
void check(int (*a)[20])
{
int i,j;
int s, b[14][22]={0};
for (i=0; i<=11; ++i)
for (j=0; j<=19; ++j)
b[i+1][j+1] = a[i][j];
for (i=1; i<=12; ++i)
{
for (j=1; j<=20; ++j)
{
s = b[i-1][j-1] + b[i-1][j] + b[i-1][j+1] + b[i][j-1]
+ b[i][j+1] + b[i+1][j-1] + b[i+1][j] + b[i+1][j+1];
a[i-1][j-1] = (s <= 1 ? 0 : (s == 2 ? b[i][j] : (s > 3 ? 0 : 1)));
}
}
}
void show(int (*a)[20])
{
for (int i=0; i<=11; ++i)
{
for (int j=0; j<=19; ++j)
cout << setw(2) << (a[i][j] == 1 ? "*" : " ");
cout << i%10 << endl;
}
cout << " 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9";
}[/CODE]
变化最后结果:下面两种状态循环
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
0
1
2
* 3
* * 4
* * 5
* 6
7
* 8
* 9
* 0
1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
0
1
2
* 3
* * 4
* * 5
* 6
7
8
* * * 9
0
1
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
[此贴子已经被作者于2007-9-21 10:02:36编辑过]