📄 d.cpp
字号:
#include<stdio.h>
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, -1, 0, 1 };
const char dir[4] = { 'E', 'S', 'W', 'N' };
const char *dst[4] = { "forward", "back", "left", "right" };
const int f[4][4] = {
{ 0, 2, 3, 1 },
{ 1, 3, 0, 2 },
{ 2, 0, 1, 3 },
{ 3, 1, 2, 0 }};
int find_st( char st[] )
{
int i;
for( i = 0; i < 4; ++i )
if( st[0] == dst[i][0] )
return i;
return -1;
}
void make_it()
{
int n, i, len, turn;
int nowx = 0, nowy = 0;
int nowDir = 3;
char st[10];
scanf( "%d", &n );
for( i = 0; i < n; ++i )
{
scanf( "%s %d", st, &len );
turn = find_st( st );
nowDir = f[nowDir][turn];
nowx += dx[nowDir] * len;
nowy += dy[nowDir] * len;
}
printf( "%d %d %c\n", nowx, nowy, dir[nowDir] );
}
int main()
{
int dataCase, i;
scanf( "%d", &dataCase );
for( i = 0; i < dataCase; ++i )
make_it();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -