Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.58 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. { // Harel Levy
  4.  //203677836
  5.  //8911003
  6. // Exercise 31
  7.  
  8.     int column,row,length,start_pos,step,speed;
  9.     int i,j,k;
  10.     int hekef;
  11.     int hekef_3_4;
  12.     char plus='+';
  13.     char minus='-';
  14.     char mul='*';
  15.     char anach='|';
  16.     char equal='=';
  17.     int snake_length;
  18.     int next_step;
  19.     char last_char_up;
  20.     char last_char_down;
  21.     char last_char_over;
  22.     int over_hekef;
  23.     int min_pos,max_pos,min_over,max_over;
  24.     int isError=0;
  25.     scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
  26.     /*set size of paramaters of matriza*/
  27.     hekef_3_4=2*(column-1)+row-1;
  28.     hekef=(row-1)*2+(column-1)*2;
  29.     /*set position for jumping in the matriza*/
  30.     next_step=start_pos;
  31.     //check legality of input
  32.     if((row==0)||(row==1)||(column==0)||(column==1))
  33.     {
  34.         printf("Error 1\n");  isError=1;
  35.     }
  36.     if((length==0)||(length>hekef))
  37.     {
  38.         printf("Error 2\n"); isError=1;
  39.     }
  40.     if((start_pos>=hekef))
  41.     {
  42.         printf("Error 3\n");  isError=1;
  43.     }
  44.     if((row<0)||(column<0)||(length<0)||(start_pos<0)||(step<0)||(speed<0))
  45.     {
  46.         printf("Error 4\n"); isError=1;
  47.     }
  48.     if(isError)
  49.         return;
  50.  
  51.     //start program
  52.     for(k=0;k<step+1;k++)
  53.     {
  54.         printf("%d\n",k);
  55.         over_hekef=0;
  56.     //set the border of frame to print
  57.         min_pos=next_step;
  58.         max_pos=min_pos+length-1;
  59.         if(max_pos>=hekef)
  60.         {
  61.             min_over=0;
  62.             max_over=max_pos-hekef;
  63.             max_pos=hekef-1;
  64.             over_hekef=1;
  65.         }
  66.         next_step=next_step+speed;
  67.         if(next_step>=hekef) next_step=next_step-hekef;
  68.         snake_length=length; //set snake length for calaculting process
  69.         if(snake_length%2==0)
  70.         {
  71.             last_char_up=plus;
  72.             last_char_down=equal;
  73.             last_char_over=plus;
  74.         }
  75.         else
  76.         {
  77.             last_char_up=equal;
  78.             last_char_down=equal;
  79.             last_char_over=equal;
  80.         }
  81.         if(over_hekef==1)
  82.             if((max_over-min_over)%2==0)
  83.             {
  84.                 last_char_over=equal;
  85.                 last_char_up=equal;
  86.                 last_char_down=plus;
  87.             }
  88.             else
  89.             {
  90.                 last_char_over=plus;
  91.                 last_char_up=plus;
  92.                 last_char_down=equal;
  93.             }
  94.         for(i=0;i<row;i++)
  95.         {
  96.             for(j=0;j<column;j++)
  97.             {
  98.                 //find if it's the first line in the frame
  99.                 if(snake_length!=0)
  100.                 {
  101.                     if((i==0)&&(j>=min_pos && j<=max_pos))
  102.                     {
  103.                         printf("%c",last_char_up);
  104.                     //set next char to be printed
  105.                     if(last_char_up==equal) last_char_up=plus;
  106.                     else last_char_up=equal;
  107.                     snake_length=snake_length-1;
  108.                     continue;
  109.                     }
  110.                     //if it's over the frame -it's cyclic
  111.                     if(over_hekef==1)
  112.                     {
  113.                         if((i==0)&&(j>=min_over && j<=max_over))
  114.                         {
  115.                             printf("%c",last_char_over);
  116.                             //set next char to be printed
  117.                             if(last_char_over==equal) last_char_over=plus;
  118.                             else last_char_over=equal;
  119.                             snake_length= snake_length-1;
  120.                             continue;
  121.                         }
  122.                     }
  123.                 //find if it's the last culumn int the frame except the
  124.                 //last char in last line-except the last char in the first line
  125.                     if(j==column-1 && i!=row-1 && i!=0 && j+i>=min_pos && j+i<=max_pos)
  126.                     {
  127.                         printf("%c",last_char_up);
  128.                         //set next char to be printed
  129.                         if(last_char_up==equal) last_char_up=plus;
  130.                         else last_char_up=equal;
  131.                             snake_length=snake_length-1;
  132.                             continue;
  133.                     }
  134.                     //if it's over the feame-it is cyclic
  135.                     if(over_hekef==1)
  136.                     {
  137.                         if(((j==column-1)&&(i!=row-1||i!=0))&&
  138.                             ((j+i>=min_over && j+i<=max_over)))
  139.                         {
  140.                             printf("%c",last_char_over);
  141.                             //set next char to be printed
  142.                             if(last_char_over==equal) last_char_over=plus;
  143.                             else last_char_over=equal;
  144.                             snake_length=snake_length-1;
  145.                             continue;
  146.                         }
  147.                     }
  148.                     //find if it's the first culumn int the frame except the
  149.                 //last char in last line-except the last char in the first column
  150.                     if((j==0 && i!=row-1 && i!=0)&&
  151.                         (hekef-i>=min_pos && hekef-i<=max_pos))
  152.                     {
  153.                         printf("%c",last_char_down);
  154.                         //set next char to be printed
  155.                         if(last_char_down==equal) last_char_down=plus;
  156.                             else last_char_down=equal;
  157.                             snake_length=snake_length-1;
  158.                             continue;
  159.                     }
  160.                     //if it's over the feame-it is cyclic
  161.                     if(over_hekef==1)
  162.                     {
  163.                         if((j==0 && i!=row-1 && i!=0)&&
  164.                             (hekef-i>=min_over && hekef-i<=max_over))
  165.                         {
  166.                             printf("%c",last_char_over);
  167.                             //set next char to be printed
  168.                             if(last_char_over==equal) last_char_over=plus;
  169.                             else last_char_over=equal;
  170.                             snake_length=snake_length-1;
  171.                             continue;
  172.                         }
  173.                     }
  174.                     //find if it's the last row in the frame
  175.                     if((i==row-1)&&(hekef_3_4-j>=min_pos && hekef_3_4-j<=max_pos))
  176.                     {
  177.                         printf("%c",last_char_down);
  178.                         //set next char to be printed
  179.                         if(last_char_down==equal) last_char_down=plus;
  180.                         else last_char_down=equal;
  181.                         snake_length=snake_length-1;
  182.                         continue;
  183.                     }
  184.                     //if it's over the frame it's cyclic
  185.                     if(over_hekef==1)
  186.                     {
  187.                         if((i==row-1)&&
  188.                             (hekef_3_4-j>=min_over && hekef_3_4-j<=max_over))
  189.                         {
  190.                             printf("%c",last_char_over);
  191.                             //set next char to be printed
  192.                             if(last_char_over==equal) last_char_over=plus;
  193.                             else last_char_over=equal;
  194.                             snake_length=snake_length-1;
  195.                             continue;
  196.                         }
  197.                     }
  198.                 }
  199.                 // now print '|' or '-' or '*'
  200.                 if((i==0)||(i==row-1))
  201.                 {
  202.                     printf("%c",minus);
  203.                     continue;
  204.                 }
  205.                 if((j==0)||(j==column-1))
  206.                 {
  207.                     printf("%c",anach);
  208.                     continue;
  209.                 }
  210.                 //print the char *
  211.                 if(((j!=0)||(j!=column-1))&&((i!=0)||(i!=row-1)))
  212.                 {
  213.                     printf("%c",mul);
  214.                     continue;
  215.                 }
  216.                 }
  217.                 printf("\n");
  218.                 }
  219.                 }
  220.                 scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
  221.                 return;
  222.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement