Submission

Status:
-xxx-x-

Score: 0

User: TirpitZ

Problemset: สะท้อน

Language: c

Time: 0.001 second

Submitted On: 2024-09-28 22:03:51

#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int pos[n][n],startx,starty;
    scanf("%d %d",&startx,&starty);
//    printf("%d %d",startx,starty);
    char direction[2];
    scanf("%s",&direction);
//    printf("%s",direction);
    //printf("%c",direction[0]+direction[1]);
    printf("\n");
    
    for(int i=0;i<n;i++)             //fill array by point
    {
        for(int k=0;k<n;k++)
        {
            pos[i][k]='.';
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int k=0;k<n;k++)
        {
            printf("%c",pos[i][k]);
        }
        printf("\n");
    }
    printf("\n");
    
    for(int i=0;i<n;i++)    pos[n-2][i]='#';
    for(int k=0;k<n-1;k++)    pos[k][n-2]='#';
    
    starty++;
    //printf("%d %d\n",startx,starty);
    pos[startx][starty]='*';
    int tempx,tempy,xchange,ychange;
    tempx=startx;    tempy=starty;
    while(1)
    {
        if(direction[0]=='N')    
        {
            if(direction[1]=='E')
            {
                xchange=1;
                ychange=-1;
            }
            else if(direction[1]=='W')
            {
                xchange=-1;
                ychange=-1;
            }
        }
        else if(direction[0]=='S')    
        {
            if(direction[1]=='E')
            {
                xchange=1;
                ychange=1;
            }
            else if(direction[1]=='W')
            {
                xchange=-1;
                ychange=1;
            }
        }
        tempx=tempx+xchange;        tempy=tempy+ychange;
        if(pos[tempx][tempy]=='#' || tempx<0 || tempy<0)
        {
            if(direction[0]=='N')
            {
                if(direction[1]=='E')        direction[1]='W';
                else if(direction[1]=='W')    direction[0]='S';
            }
            else if(direction[0]=='S')
            {
                if(direction[1]=='W')        direction[1]='E';
                else if(direction[1]=='E')    direction[0]='N';
            }
        }
        else pos[tempx][tempy] = '*';
        if(tempx==startx && tempy==starty)    break;
    }
    for(int i=0;i<n;i++)
    {
        for(int k=0;k<n;k++)
        {
            printf("%c",pos[i][k]);
        }
        printf("\n");
    }
    
 }