Life Game-cww

Posted by Cww97 on 2016-03-14

版权声明:本文为博主原创文章,未经博主允许不得转载。原文所在http://blog.csdn.net/cww97 https://blog.csdn.net/cww97/article/details/50887843

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=22,M=66;
const int dx[]={-1,0,1,0,-1,-1,1,1};
const int dy[]={0,-1,0,1,-1,1,-1,1};
int g[N][M],gg[N][M],x,y,n=20,m=60;
bool ok[N][M];
char ch;

int main(){
puts("Welcome");
for (;scanf("%d%d",&x,&y)==2&&!(x==-1&&y==-1);){
if (ok[x][y])continue;
for (int i=0;i<8;i++) g[x+dx[i]][y+dy[i]]++;
ok[x][y]=1;
}
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++)
if (ok[i][j])printf("*");
else printf("-");
puts("");
}
puts("fuck or not?");
for (;cin>>ch&&ch!='n';){
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)gg[i][j]=g[i][j];
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (ok[i][j]&&(gg[i][j]!=2&&gg[i][j]!=3)){
for (int di=0;di<8;di++) g[i+dx[di]][j+dy[di]]--;
ok[i][j]=0;
}
if ((!ok[i][j])&&gg[i][j]==3){
for (int di=0;di<8;di++) g[i+dx[di]][j+dy[di]]++;
ok[i][j]=1;
}
if (ok[i][j])printf("*");else printf("-");
}
puts("");
}
puts("fuck or not?");
}
return 0;
}