NCPC26 fixing folder and file placments
This commit is contained in:
3 files changed
No files matched your search
Generated
-77
@@ -1,77 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int ship_x, ship_y;
|
||||
int treasure_x, treasure_y;
|
||||
int direction_x, direction_y;
|
||||
int movement_help;
|
||||
|
||||
scanf("%d %d", &ship_x, &ship_y);
|
||||
scanf("%d %d", &treasure_x, &treasure_y);
|
||||
|
||||
|
||||
|
||||
while (((ship_x == treasure_x) && (ship_y == treasure_y))==0){
|
||||
direction_x = ship_x - treasure_x;
|
||||
direction_y = ship_y - treasure_y;
|
||||
|
||||
//diagonal movement
|
||||
if (abs(direction_x) == abs(direction_y)){
|
||||
//NortEeast movment
|
||||
if((direction_x < 0) && (direction_y < 0)){
|
||||
printf("NE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//NortWest movement
|
||||
else if((direction_x > 0) && (direction_y < 0)){
|
||||
printf("NW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthWest movement
|
||||
else if((direction_x > 0) && (direction_y > 0)){
|
||||
printf("SW\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
//SouthEast movement
|
||||
else if((direction_x < 0) && (direction_y > 0)){
|
||||
printf("SE\n");
|
||||
ship_x -= direction_x;
|
||||
ship_y -= direction_y;
|
||||
}
|
||||
}
|
||||
else if((abs(direction_x) != abs(direction_y))){
|
||||
//horisontal / vertical movement
|
||||
if(abs(direction_x) > abs(direction_y)){
|
||||
movement_help = abs(abs(direction_x) - abs(direction_y));
|
||||
//East movement
|
||||
if(direction_x < 0){
|
||||
printf("E\n");
|
||||
ship_x += movement_help;
|
||||
}
|
||||
//West movement
|
||||
if(direction_x > 0){
|
||||
printf("W\n");
|
||||
ship_x -= movement_help;
|
||||
}
|
||||
}
|
||||
if(abs(direction_x) < abs(direction_y)){
|
||||
movement_help = abs( abs(direction_y) - abs(direction_x));
|
||||
//North Movement
|
||||
if(direction_y < 0){
|
||||
printf("N\n");
|
||||
ship_y += movement_help;
|
||||
}
|
||||
//South Movement
|
||||
if(direction_y > 0){
|
||||
printf("S\n");
|
||||
ship_y -= movement_help;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
BIN
Binary file not shown.
Generated
Whitespace-only changes.
Reference in new issue
Block a user