c

power of thor episode 1

problem sayfasi

kodun yazimi sirasinda hazirlanan gorsel: thor

// yasin tasan - may 2018
// #include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
int lightX; // the X position of the light of power
int lightY; // the Y position of the light of power
int initialTX;// Thor's starting X position
int initialTY; // Thor's starting Y position
scanf("%d%d%d%d", &lightX, &lightY, &initialTX, &initialTY);

// case 0 
// Thor position = (5,4). Light position = (31,4). Energy = 100

// case 1 
// Thor position = (31,17). Light position = (31,4). Energy = 13

// case 2 
// Thor position = (31,4). Light position = (0,17). Energy = 44

// case 3 
// Thor position = (0,0). Light position = (36,17). Energy = 36

int real_x = initialTX;
int real_y = initialTY;

// game loop
while (1) 
{
    int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
    scanf("%d", &remainingTurns);

    if (initialTX < lightX && initialTY == lightY )
    {
        fprintf(stderr, "condition 0\n");
        printf("E\n");
        real_x++;
        fprintf(stderr, "x = %d\n",real_x);
    }
    if (initialTX > lightX && initialTY == lightY )
    {
        fprintf(stderr, "condition 1\n");
        printf("W\n");
        real_x--;
        fprintf(stderr, "x = %d\n",real_x);
    }
    if (initialTX == lightX && initialTY > lightY )
    {
        fprintf(stderr, "condition 2\n");
        printf("N\n");
        real_y--;
        fprintf(stderr, "y = %d\n",real_y);
    }
    if (initialTX == lightX && initialTY < lightY )
    {
        fprintf(stderr, "condition 3\n");
        printf("S\n");
        real_y++;
        fprintf(stderr, "y = %d\n",real_y);
    }       

    if (initialTX > lightX && initialTY < lightY )
    {
        fprintf(stderr, "condition 4\n");
        if(real_x > lightX+lightY-initialTY)
        {
            printf("W\n");
            real_x--;
            fprintf(stderr, "x = %d\n",real_x);
        }
        else 
        {
            printf("SW\n");
            real_x--;
            real_y++;
            fprintf(stderr, "x = %d\n",real_x);
            fprintf(stderr, "y = %d\n",real_y);
        }
    }   
    if (initialTX < lightX && initialTY < lightY )
    {
        fprintf(stderr, "condition 5\n");
        if(real_x < lightX-(lightY-initialTY))
        {
            printf("E\n");
            real_x++;
            fprintf(stderr, "x = %d\n",real_x);
        }
        else 
        {
            printf("SE\n");
            real_x++;
            real_y++;
            fprintf(stderr, "x = %d\n",real_x);
            fprintf(stderr, "y = %d\n",real_y);
        }
    }       
    if (initialTX < lightX && initialTY > lightY )
    {
        fprintf(stderr, "condition 6\n");
        if(real_x < lightX-(initialTY-lightY)) 
        {
            printf("E\n");
            real_x++;
            fprintf(stderr, "x = %d\n",real_x);
        }
        else 
        {
            printf("NE\n");
            real_x++;
            real_y--;
            fprintf(stderr, "x = %d\n",real_x);
            fprintf(stderr, "y = %d\n",real_y);
        }
    }       
    if (initialTX > lightX && initialTY > lightY )
    {
        fprintf(stderr, "condition 7\n");
        if(real_x > lightX+(initialTY-lightY)) 
        {
            printf("W\n");
            real_x--;
            fprintf(stderr, "x = %d\n",real_x);
        }
        else 
        {
            printf("NW\n");
            real_x--;
            real_y--;
            fprintf(stderr, "x = %d\n",real_x);
            fprintf(stderr, "y = %d\n",real_y);
        }
    }   
}

return 0;
}