0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 19:36:28 +00:00
OI-codes/Luogu/P2689/P2689.cpp

32 lines
666 B
C++
Raw Normal View History

2021-11-19 09:01:13 +00:00
#include <bits/stdc++.h>
2020-11-03 08:11:32 +00:00
using namespace std;
int main() {
int x1, y1, x2, y2, t, ans = 0;
char c;
cin >> x1 >> y1 >> x2 >> y2 >> t;
2021-11-19 09:01:13 +00:00
for (int i = 1; i <= t; i++) {
2020-11-03 08:11:32 +00:00
cin >> c;
2021-11-19 09:01:13 +00:00
if (c == 'E' && y1 < y2) {
2020-11-03 08:11:32 +00:00
y1++;
ans++;
2021-11-19 09:01:13 +00:00
} else if (c == 'W' && y1 > y2) {
2020-11-03 08:11:32 +00:00
y1--;
ans++;
2021-11-19 09:01:13 +00:00
} else if (c == 'N' && x1 < x2) {
2020-11-03 08:11:32 +00:00
x1++;
ans++;
2021-11-19 09:01:13 +00:00
} else if (c == 'S' && x1 > x2) {
2020-11-03 08:11:32 +00:00
x1--;
ans++;
}
2021-11-19 09:01:13 +00:00
if (x1 == x2 && y1 == y2) {
2020-11-03 08:11:32 +00:00
cout << ans << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}