'commit'
This commit is contained in:
47
LuoGu/RuMen/P2689.cpp
Normal file
47
LuoGu/RuMen/P2689.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user