⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 problem3.cpp

📁 This project asks you to write a program that allows you to specify an initial configuration. The p
💻 CPP
字号:
#include <iostream>using namespace std;char world[8][8]={{'*',' ',' ','*','*',' ',' ',' '},               {'*',' ','*','*',' ','*','*','*'},               {'*',' ','*','*','*','*',' ','*'},               {'*',' ','*',' ',' ','*',' ','*'},               {' ','*',' ',' ',' ',' ',' ',' '},               {' ','*',' ','*',' ',' ','*',' '},               {'*',' ',' ','*',' ',' ','*',' '},               {'*',' ','*',' ','*',' ',' ','*'}};void generation(){	int i,j;	//copy the world table        char copyworld[8][8];	for(i=0;i<8;i++){                for(j=0;j<8;j++){                        copyworld[i][j]=world[i][j];                }        }		for(i=0;i<8;i++){		for(j=0;j<8;j++){			int neighbor=0;			if((i-1>=0)&&(j-1>=0)&&'*'==copyworld[i-1][j-1])neighbor++;			if((i-1>=0)&&'*'==copyworld[i-1][j])neighbor++;			if((i-1>=0)&&(j+1<8)&&'*'==copyworld[i-1][j+1])neighbor++;			if((j-1>=0)&&'*'==copyworld[i][j-1])neighbor++;			if((j+1<8)&&'*'==copyworld[i][j+1])neighbor++;			if((i+1<8)&&(j-1>=0)&&'*'==copyworld[i+1][j-1])neighbor++;			if((i+1<8)&&'*'==copyworld[i+1][j])neighbor++;			if((i+1<8)&&(j+1<8)&&'*'==copyworld[i+1][j+1])neighbor++;			if('*'==copyworld[i][j]){				if(0==neighbor||1==neighbor||neighbor>3){					world[i][j]=' ';				}			}			else{				if(3==neighbor){					world[i][j]='*';				}			}				}	}}void display(){	cout<<"-----------------\n";	int i,j;	for(i=0;i<8;i++){		for(j=0;j<8;j++){			cout<<"|"<<world[i][j];		}		cout<<"|"<<endl;	}	cout<<"-----------------\n";}int main(){	cout<<"The initial world:\n";	display();		cout<<"After one generation:\n";        generation();	display();	return 0;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -