描述
罗少在玩一个游戏,用 W S A D 分别控制角色进行 上 下 左 右 移动,我们可以把地图看作一个二维平面,罗少初始站在原点,现在他操作了 n 次,请你输出他的位置。
输入
第一行是一个正整数 n 代表测试案例的数量。(1 <= n <= 100)
每组案例是一个仅包含字符WSAD的字符串 t 代表罗少的操作。(1 <= length(t) <= 100)
输出
针对每组案例,输出罗少操作以后所在位置的横纵坐标,两者之间用空格隔开,然后换行。
样例输入
2
WWW
SSD
样例输出
0 3
1 -2
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<random>
using namespace std;
typedef long long int ll;
int main()
{
int n;
cin >> n;
while (n--)
{
int x = 0, y = 0;
string t;
cin >> t;
for (int i = 0; i < t.length(); i++)
{
if (t[i] == 'W')
{
y++;
}
if (t[i] == 'S')
{
y--;
}
if (t[i] == 'A')
{
x--;
}
if (t[i] == 'D')
{
x++;
}
}
cout << x << " " << y << endl;
}
return 0;
}
//娱乐题,高兴就好0.0