mirror of
https://github.com/Oxbian/CodingGame.git
synced 2025-07-07 12:24:23 +02:00
Adding the first coding game Challenges
This commit is contained in:
49
Easy_Challenges/power_of_thor_1.c
Normal file
49
Easy_Challenges/power_of_thor_1.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// the X position of the light of power
|
||||
int light_x;
|
||||
// the Y position of the light of power
|
||||
int light_y;
|
||||
// Thor's starting X position
|
||||
int initial_tx;
|
||||
// Thor's starting Y position
|
||||
int initial_ty;
|
||||
|
||||
scanf("%d%d%d%d", &light_x, &light_y, &initial_tx, &initial_ty);
|
||||
|
||||
// game loop
|
||||
while (1)
|
||||
{
|
||||
// The remaining amount of turns Thor can move. Do not remove this line.
|
||||
int remaining_turns;
|
||||
scanf("%d", &remaining_turns);
|
||||
|
||||
char *dirX = "";
|
||||
char *dirY = "";
|
||||
|
||||
if ((initial_tx >= 0 && initial_tx < 40) && (initial_ty >= 0 && initial_ty < 18))
|
||||
{
|
||||
if (initial_tx > light_x)
|
||||
dirX = "W", initial_tx--;
|
||||
else if (initial_tx < light_x)
|
||||
dirX = "E", initial_tx++;
|
||||
else
|
||||
dirX = "";
|
||||
|
||||
if (initial_ty > light_y)
|
||||
dirY = "N", initial_ty--;
|
||||
else if (initial_ty < light_y)
|
||||
dirY = "S", initial_ty++;
|
||||
else
|
||||
dirY = "";
|
||||
}
|
||||
printf("%s%s\n", dirY, dirX);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user