Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- { // Harel Levy
- //203677836
- //8911003
- // Exercise 31
- int column,row,length,start_pos,step,speed;
- int i,j,k;
- int hekef;
- int hekef_3_4;
- char plus='+';
- char minus='-';
- char mul='*';
- char anach='|';
- char equal='=';
- int snake_length;
- int next_step;
- char last_char_up;
- char last_char_down;
- char last_char_over;
- int over_hekef;
- int min_pos,max_pos,min_over,max_over;
- int isError=0;
- scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
- /*set size of paramaters of matriza*/
- hekef_3_4=2*(column-1)+row-1;
- hekef=(row-1)*2+(column-1)*2;
- /*set position for jumping in the matriza*/
- next_step=start_pos;
- //check legality of input
- if((row==0)||(row==1)||(column==0)||(column==1))
- {
- printf("Error 1\n"); isError=1;
- }
- if((length==0)||(length>hekef))
- {
- printf("Error 2\n"); isError=1;
- }
- if((start_pos>=hekef))
- {
- printf("Error 3\n"); isError=1;
- }
- if((row<0)||(column<0)||(length<0)||(start_pos<0)||(step<0)||(speed<0))
- {
- printf("Error 4\n"); isError=1;
- }
- if(isError)
- return;
- //start program
- for(k=0;k<step+1;k++)
- {
- printf("%d\n",k);
- over_hekef=0;
- //set the border of frame to print
- min_pos=next_step;
- max_pos=min_pos+length-1;
- if(max_pos>=hekef)
- {
- min_over=0;
- max_over=max_pos-hekef;
- max_pos=hekef-1;
- over_hekef=1;
- }
- next_step=next_step+speed;
- if(next_step>=hekef) next_step=next_step-hekef;
- snake_length=length; //set snake length for calaculting process
- if(snake_length%2==0)
- {
- last_char_up=plus;
- last_char_down=equal;
- last_char_over=plus;
- }
- else
- {
- last_char_up=equal;
- last_char_down=equal;
- last_char_over=equal;
- }
- if(over_hekef==1)
- if((max_over-min_over)%2==0)
- {
- last_char_over=equal;
- last_char_up=equal;
- last_char_down=plus;
- }
- else
- {
- last_char_over=plus;
- last_char_up=plus;
- last_char_down=equal;
- }
- for(i=0;i<row;i++)
- {
- for(j=0;j<column;j++)
- {
- //find if it's the first line in the frame
- if(snake_length!=0)
- {
- if((i==0)&&(j>=min_pos && j<=max_pos))
- {
- printf("%c",last_char_up);
- //set next char to be printed
- if(last_char_up==equal) last_char_up=plus;
- else last_char_up=equal;
- snake_length=snake_length-1;
- continue;
- }
- //if it's over the frame -it's cyclic
- if(over_hekef==1)
- {
- if((i==0)&&(j>=min_over && j<=max_over))
- {
- printf("%c",last_char_over);
- //set next char to be printed
- if(last_char_over==equal) last_char_over=plus;
- else last_char_over=equal;
- snake_length= snake_length-1;
- continue;
- }
- }
- //find if it's the last culumn int the frame except the
- //last char in last line-except the last char in the first line
- if(j==column-1 && i!=row-1 && i!=0 && j+i>=min_pos && j+i<=max_pos)
- {
- printf("%c",last_char_up);
- //set next char to be printed
- if(last_char_up==equal) last_char_up=plus;
- else last_char_up=equal;
- snake_length=snake_length-1;
- continue;
- }
- //if it's over the feame-it is cyclic
- if(over_hekef==1)
- {
- if(((j==column-1)&&(i!=row-1||i!=0))&&
- ((j+i>=min_over && j+i<=max_over)))
- {
- printf("%c",last_char_over);
- //set next char to be printed
- if(last_char_over==equal) last_char_over=plus;
- else last_char_over=equal;
- snake_length=snake_length-1;
- continue;
- }
- }
- //find if it's the first culumn int the frame except the
- //last char in last line-except the last char in the first column
- if((j==0 && i!=row-1 && i!=0)&&
- (hekef-i>=min_pos && hekef-i<=max_pos))
- {
- printf("%c",last_char_down);
- //set next char to be printed
- if(last_char_down==equal) last_char_down=plus;
- else last_char_down=equal;
- snake_length=snake_length-1;
- continue;
- }
- //if it's over the feame-it is cyclic
- if(over_hekef==1)
- {
- if((j==0 && i!=row-1 && i!=0)&&
- (hekef-i>=min_over && hekef-i<=max_over))
- {
- printf("%c",last_char_over);
- //set next char to be printed
- if(last_char_over==equal) last_char_over=plus;
- else last_char_over=equal;
- snake_length=snake_length-1;
- continue;
- }
- }
- //find if it's the last row in the frame
- if((i==row-1)&&(hekef_3_4-j>=min_pos && hekef_3_4-j<=max_pos))
- {
- printf("%c",last_char_down);
- //set next char to be printed
- if(last_char_down==equal) last_char_down=plus;
- else last_char_down=equal;
- snake_length=snake_length-1;
- continue;
- }
- //if it's over the frame it's cyclic
- if(over_hekef==1)
- {
- if((i==row-1)&&
- (hekef_3_4-j>=min_over && hekef_3_4-j<=max_over))
- {
- printf("%c",last_char_over);
- //set next char to be printed
- if(last_char_over==equal) last_char_over=plus;
- else last_char_over=equal;
- snake_length=snake_length-1;
- continue;
- }
- }
- }
- // now print '|' or '-' or '*'
- if((i==0)||(i==row-1))
- {
- printf("%c",minus);
- continue;
- }
- if((j==0)||(j==column-1))
- {
- printf("%c",anach);
- continue;
- }
- //print the char *
- if(((j!=0)||(j!=column-1))&&((i!=0)||(i!=row-1)))
- {
- printf("%c",mul);
- continue;
- }
- }
- printf("\n");
- }
- }
- scanf("%d%d%d%d%d%d",&column,&row,&length,&start_pos,&step,&speed);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement