About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

সোমবার, ১৪ আগস্ট, ২০১৭

uva 118 solution

#include<stdio.h>
#define ll long long
int row, col;
int ary[100][100];
char d[10], str[102];
int main()
{
 //freopen("Text.txt", "r", stdin);
 scanf("%d %d", &row, &col);

 for (int i = 0; i <= row; i++)
  for (int j = 0; j <= col; j++) ary[i][j] = 0;
 int r, c;
 while (scanf("%d %d %s", &r, &c, d) == 3)
 {
  scanf("%s", str);
  char dir = d[0];
  bool flag = true;
  for (int i = 0; str[i] != '\0'; i++)
  {
   if (str[i] == 'R' || str[i] == 'L')
   {
    //printf("%d\n",i+1);
    if (dir == 'E')
    {
     str[i] == 'R' ? dir = 'S' : dir = 'N';
    }
    else if (dir == 'N')
    {
     str[i] == 'R' ? dir = 'E' : dir = 'W';
    }
    else if (dir == 'S')
    {
     str[i] == 'R' ? dir = 'W' : dir = 'E';
    }
    else
    {
     str[i] == 'R' ? dir = 'N' : dir = 'S';
    }
    //printf("---%c----", dir);
   }
   else
   {
    if (dir == 'E')
    {
     if (r + 1 <= row) r += 1;
     else
     {
      if (ary[r][c] == 0)
      {
       ary[r][c] = 1;
       printf("%d %d %c LOST\n", r, c, dir);
       flag = false;
       break;
      }
      else continue;
     }
    }

    if (dir == 'N')
    {
     if (c + 1 <= col) c += 1;
     else
     {
      if (ary[r][c] == 0)
      {
       ary[r][c] = 1;
       printf("%d %d %c LOST\n", r, c, dir);
       flag = false;
       break;
      }
      else continue;
     }
    }

    if (dir == 'S')
    {
     if (c - 1 >= 0) c -= 1;
     else
     {
      if (ary[r][c] == 0)
      {
       ary[r][c] = 1;
       printf("%d %d %c LOST\n", r, c, dir);
       flag = false;
       break;
      }
      else continue;
     }
    }

    if (dir == 'W')
    {
     if (r - 1 >= 0) r -= 1;
     else
     {
      if (ary[r][c] == 0)
      {
       ary[r][c] = 1;
       printf("%d %d %c LOST\n", r, c, dir);
       flag = false;
       break;
      }
      else continue;
     }
    }

    //printf("%d %d\n", r, c);
   }
   // printf("%c\n",dir);
  }
  if (flag) printf("%d %d %c\n", r, c, dir);
 }

 return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন