http://acm.nyist.net/JudgeOnline/problem.php?pid=371
#include<stdio.h>
#include<string.h>
int main()
{
char ch[110],state;
int i,j,T,len;
int x,y;
scanf("%d",&T);
while(T--)
{
scanf("%s",ch);
len=strlen(ch);
x=0;y=0;state='N';
for(i=0;i<len;i++)
{
if(ch[i]=='L')
{
if(state=='N')
state='W';
else if(state=='W')
state='S';
else if(state=='S')
state='E';
else if(state=='E')
state='N';
}
if(ch[i]=='R')
{
if(state=='N')
state='E';
else if(state=='E')
state='S';
else if(state=='S')
state='W';
else if(state=='W')
state='N';
}
if(ch[i]=='M')
{
if(state=='N')
++y;
else if(state=='W')
--x;
else if(state=='S')
--y;
else if(state=='E')
++x;
}
}
printf("%d %d %c\n",x,y,state);
}
return 0;
}