nyoj-371-机器人II

来源:互联网 发布:福建厦门seo 编辑:程序博客网 时间:2024/05/22 15:24

#include<stdio.h>
#include<string.h>
char a[105];
int main()
{
 int s;
 scanf("%d",&s);
 while(s--)
 {
  int n,i,j,x,y;
  scanf("%s",a);
  n=strlen(a);
  j=x=y=0;
  for(i=0;i<n;i++)
  {
  if(a[i]=='R')
    j++;
   else if(a[i]=='L')
    j--;
   else
   {
    if(j%4==0)
     y++;
    else if(j%4==1||j%4==-3)
     x++;
    else if(j%4==2||j%4==-2)
     y--;
    else
     x--;
   }
  }
  printf("%d %d ",x,y);
  if(j%4==0)
   printf("N\n");
  else if(j%4==1||j%4==-3)
   printf("E\n");
  else if(j%4==2||j%4==-2)
   printf("S\n");
  else
   printf("W\n");
 }
 return 0;
}

 

 

 


 

原创粉丝点击