You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
955 B

#include <bits/stdc++.h>
using namespace std;
char q[66];
int ans;
//南风,向北走
//西风,向东走
//东风,向西走
//北风,向南走
int main() {
int x, y, x1, y1;
cin >> x >> y >> x1 >> y1;
int n;
cin >> n;
for (int i = 0; i < n; i++) {//输入环节
cin >> q[i];
}
for (int i = 0; i < n; i++) {
if (q[i] == 'N' && x < x1) {
x++;
ans++;
continue;
}
if (q[i] == 'S' && x > x1) {
x--;
ans++;
continue;
}
if (q[i] == 'E' && y < y1) {
y++;
ans++;
continue;
}
if (q[i] == 'W' && y > y1) {
y--;
ans++;
continue;
}
if (x == x1 && y == y1) {
cout << ans << endl;
return 0;
}
}
puts("-1");
return 0;
}