链接
题意
思路
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
set<pair<pair<int,int>,pair<int,int>>>st;
string s;
int x, y, lastx, lasty, ans;
int main()
{
int T;
cin >> T;
while(T--){
lastx = 0; lasty = 0;
x = 0; y = 0; ans = 0;
st.clear();
cin >> s;
for(int i = 0; i <= s.size()-1; i++){
if(s[i]=='N') y++;
else if(s[i]=='S') y--;
else if(s[i]=='W') x--;
else if(s[i]=='E') x++;
if(st.count({{x,y},{lastx,lasty}}))ans += 1;
else ans += 5,
st.insert({{x,y},{lastx,lasty}}),
st.insert({{lastx,lasty},{x,y}});
lastx = x;
lasty = y;
}
cout << ans << "\n";
}
return 0;
}