我也是
```
#include<iostream>
using namespace std;
int main()
{
int east=0,south=0,west=0,north=0;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int T;
cin>>T;
while(T--)
{
char t;
cin>>t;
switch(t)
{
case 'E':east++;
case 'S':south++;
case 'W':west++;
case 'N':north++;
}
}
if(x1<=x2)
{
if(y1<=y2)
{
if(x2-x1<=east&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
else
{
if(y1<=y2)
{
if(x1-x2<=east&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
return 0;
}
by xxc123 @ 2023-04-04 23:06:35
改后还错
```
#include<iostream>
using namespace std;
int main()
{
int east=0,south=0,west=0,north=0;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int T;
cin>>T;
while(T--)
{
char t;
cin>>t;
switch(t)
{
case 'E':east++;
case 'S':south++;
case 'W':west++;
case 'N':north++;
}
}
if(x1<=x2)
{
if(y1<=y2)
{
if(x2-x1<=east&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=south)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
else
{
if(y1<=y2)
{
if(x1-x2<=east&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
else
{
if(x1-x2<=west&&y2-y1<=north)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
else
{
cout<<-1<<endl;
return 0;
}
}
}
return 0;
}
by xxc123 @ 2023-04-05 18:54:54
@[Unaccepted_Error](/user/594405)
正确代码应是这样
```
#include<iostream>
using namespace std;
int main()
{
int east=0,south=0,west=0,north=0;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
char t;
cin>>t;
switch(t)
{
case 'E':east++;break;
case 'S':south++;break;
case 'W':west++;break;
case 'N':north++;break;
}
}
if(x1<=x2)
{
if(y1<=y2)
{
if(x2-x1<=north&&y2-y1<=east)
{
cout<<x2-x1+y2-y1<<endl;
return 0;
}
}
else
{
if(x2-x1<=north&&y1-y2<=west)
{
cout<<x2-x1+y1-y2<<endl;
return 0;
}
}
}
else
{
if(y1<=y2)
{
if(x1-x2<=south&&y2-y1<=east)
{
cout<<x1-x2+y2-y1<<endl;
return 0;
}
}
else
{
if(x1-x2<=south&&y1-y2<=west)
{
cout<<x1-x2+y1-y2<<endl;
return 0;
}
}
}
cout<<-1<<endl;
return 0;
}
by xxc123 @ 2023-04-05 19:29:07