Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cassert>
  3. #include <stdlib.h>
  4.  
  5. using namespace std ;
  6.  
  7. class Cellular {
  8. private :
  9. int Regula ;
  10. char *RegulaLancuchBin ;
  11. public :
  12.  
  13.  Cellular() {
  14. RegulaLancuchBin=new char [ 8 ] ;
  15. if ( ! RegulaLancuchBin ){
  16. cout<<"brak pamieci dla tablicy RegulaLancuchBin[8]"<<endl ;
  17. }
  18. }
  19.  
  20. void WczytajRegule ( int dec ){
  21. assert ( dec>=0 && dec <256);
  22. Regula=dec ;
  23. i_to_s (Regula , RegulaLancuchBin , 2 , 8 ) ;
  24. };
  25.  
  26. void i_to_s ( int xx , char * lanc , int nn , int DLUG) ;
  27. void PokazRegule() {
  28. cout<<"Regula "<<Regula<<": "<<RegulaLancuchBin<<endl ;
  29. }
  30. int ZakodujSasiedztwo ( const int &lewy , const int &srodek , const int &prawy ){
  31.     int liczba_dekod , reg , ref ;
  32.     char znak , zero='0';
  33.     ref=(int ) zero ;
  34.  
  35.     reg=prawy+2*srodek+4*lewy ;
  36.     znak=*(RegulaLancuchBin+7−reg ) ;
  37.     liczba_dekod =(( int ) ( znak))− ref ;
  38.     return liczba_dekod ;
  39. }
  40. };
  41.  
  42.  
  43.  void Cellular :: i_to_s ( int xx , char * lanc , int nn , int DLUG){
  44. long x=xx ;
  45. int l=DLUG−1;
  46. long n = nn ;
  47. int j ;
  48.  
  49. for ( j =0; j<DLUG; j++) *( lanc+j )='0' ;
  50. *( lanc+DLUG)='"0' ;
  51.  
  52.  if ( ! x ) ;
  53.  else
  54.  {
  55. do
  56. {
  57. *( l anc+l )=0+x % n ;
  58.  
  59.  x/=n ;
  60.  
  61. l −−;
  62.  } while ( x ) ;
  63.  for ( j =0; j<l ; j++) *( l anc+j )=0;
  64.  *( lanc+DLUG)=’“0;
  65.  
  66.  }
  67.  }
  68.  
  69.  void WarunkiPeriodyczne ( int &i_left , const int &i , int &i_right , const int &L ) ;
  70.  
  71.  int main ( int argc , char ** argv ){
  72.  if ( argc !=4){
  73.  cout<<"Poprawny format polecenia: " ;
  74.  cout<<argv [0]<<" nr˙reg˙Wolframa l˙krok˙czas l˙wezlow"<<endl ;
  75.  return 0 ;
  76.  }
  77.  
  78.  int reg=atoi ( argv [ 1 ] ) ;
  79.  int T=atoi ( argv [ 2 ] ) ;
  80.  int L=atoi ( argv [ 3 ] ) ;
  81.  
  82.  Cellular A;
  83.  A.WczytajRegule ( reg ) ;
  84.  A. PokazRegule ( ) ;
  85.  
  86.  int *Dywan=new int [L ] ;
  87.  int *DD=new int [L ] ;
  88.  
  89.  for ( int i =0; i<L; i++){
  90.  Dywan [ i ]=0;
  91.  }
  92.  
  93.  
  94.  int ilewy , isrod , iprawy ;
  95.  int slewy , ssrod , sprawy ;
  96.  
  97.  *(Dywan+L/2)=1; // s t a r t
  98.  
  99.  for ( int t=0; t<T; t++){
  100.  
  101.  for ( int i =0; i<L; i++){
  102. i f ( * (Dywan+i )==1)cout<<*; else cout<<” ” ;
  103.  }
  104.  cout<<endl ;
  105.  
  106.  
  107.  for ( int i =0; i<L; i++){
  108.  ilewy=i −1; isrod=i ; iprawy=i +1;
  109.  WarunkiPeriodyczne ( ilewy , isrod , iprawy ,L ) ;
  110.  slewy=*(Dywan+ilewy ) ; s s r od=*(Dywan+isrod ) ; sprawy=*(Dywan+iprawy ) ;
  111.  
  112.  *(DD+i )=A. ZakodujSasiedztwo ( slewy , ssrod , sprawy ) ;
  113.  }
  114.  
  115.  for ( int i =0; i<L; i++){
  116.  *(Dywan+i )=*(DD+i ) ;
  117.  }
  118.  }
  119.  
  120.  
  121.  return 0 ;
  122.  }
  123.  
  124.  void WarunkiPeriodyczne ( int &i_lewy , const int &i , int &i_prawy , const int &L){
  125.  if ( i==0) i_lewy=L−1;
  126.  else {
  127.  if ( i==L−1) i_prawy=0;
  128.  }
  129.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement