```cpp
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int main(){
char n;
int a,b,c,d,e,ans=0;
cin>>a>>b>>c>>d>>e;
for(int i=1;i<=e;i++){
cin>>n;
if(n=='N'&&a<c)a++,ans++;
else if(n=='S'&&a>c)a--,ans++;
else if(n=='E'&&b<d)b++,ans++;
else if(n=='W'&&b>d)b--,ans++;
}
if(a==c&&b==d)cout<<ans;
else cout<<"-1";
return 0;
}
```
试试这个
by liverxiwo @ 2024-02-02 20:37:30
@[Dbr_is_juruo](/user/762086)
by liverxiwo @ 2024-02-02 20:37:42