|
//进化论。。。。。。哈哈哈哈
#include<iostream>
using namespace std;
void life_circle(int [][20],int [][20]);
void life_info(int a[][20],int x,int y)
{
a[x][y]=1;
}
int main()
{
int a[20][20],b[20][20];
int i,j,x,y,count,times;
while(1)
{
for(i=0;i<21;i++)
{
for(j=0;j<21;j++)
{
a[i][j]=0;
b[i][j]=0;
}
}
cout<<"How many seeds do you want to give birth to?"<<endl;
cin>>count;
for(i=0;i<count;i++)
{
cout<<"The information of the seeds please"<<endl;
cin>>x>>y;
life_info(a,x,y);
}
cout<<"How many steps to go ahead?"<<endl;
cin>>times;
for(i=0;i<times;i++)
life_circle(a,b);
}
system("pause");
return 0;
}
void life_circle(int a[][20],int b[][20])
{
int i,j;
for(i=1;i<20;i++)
{for(j=1;j<20;j++)
{
b[i][j]=a[i-1][j-1]+a[i-1][j]+a[i-1][j+1]+a[i][j-1]+a[i][j+1]+a[i+1][j-1]+a[i+1][j]+a[i+1][j+1];
}
}
for(i=1;i<20;i++)
{
for(j=1;j<20;j++)
{
if(b[i][j]==3)
a[i][j]=1;
else
if(b[i][j]>3||b[i][j]<2)
a[i][j]=0;
else
;
if(a[i][j]==1)
cout<<"*";
else
cout<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<endl;
cout<<endl;
}
观察微生物的变化 过多过少的邻居都会使微生物死亡 |
|