?? fig.9.cpp
字號:
//Fig.9
#include "stdafx.h"
#include<iostream.h>
int a[200],b[8], i,temp[200];
int match(int l,int m,int n);
int _tmain(int argc, _TCHAR* argv[])
{
int j,n,time_steps;
cout<<"Please enter the number of sites n: "<<endl;
cin>>n;
cout<<"Please enter time_steps: "<<endl;
cin>>time_steps;
int R,k=7;
cout<<"Please enter the rule R: "<<endl;
cin>>R;
cout<<"(";
while(R>0)
{
b[k]=R%2;
R=R/2;
k--;
}
for(k=0;k<8;k++)
cout<<b[k];
cout<<")"<<endl;
// 將十進制R轉化為二進制;
cout.width(4);
cout<<"0"<<":";
for(i=0;i<n;i++)
{
if(i==int((n-1)/2))
{
a[i]=1;
cout<<"*";
}
else
{
a[i]=0;
cout<<" ";
}
}
cout<<endl;
//初始時刻中間格點值為1,其它格點值為0;
for(j=1;j<=time_steps;j++)
{
cout.width(4);
cout<<j<<":";
for(i=0;i<n;i++)
temp[i]=a[i];
for(i=0;i<n;i++)
{
if((i==0)||(i==(n-1)))
{
a[i]=0;
cout<<" ";
}
//零邊界條件;
else
match(temp[i-1],temp[i],temp[i+1]);
}
cout<<endl;
}
//每個格點同步地按局域規則進行演化;
return 0;
}
int match(int l,int m,int n)
{
if(l==1&&m==1&&n)
a[i]=b[0];
if(l==1&&m==1&&n==0)
a[i]=b[1];
if(l==1&&m==0&&n==1)
a[i]=b[2];
if(l==1&&m==0&&n==0)
a[i]=b[3];
if(l==0&&m==1&&n==1)
a[i]=b[4];
if(l==0&&m==1&&n==0)
a[i]=b[5];
if(l==0&&m==0&&n==1)
a[i]=b[6];
if(l==0&&m==0&&n==0)
a[i]=b[7];
if(a[i]==1)
cout<<"*";
else
cout<<" ";
return a[i];
}
//定義match函數;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -