思路
画一个坐标轴,原点就是当前位置,根据目标所在位置模拟即可。
Solution
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T;cin>>T;
while(T--){
int x,y,x1,y1,q;char dir;cin>>x>>y>>dir>>x1>>y1;
if(dir=='N'){
if(y1>y){
if(x1==x)cout<<0<<'\n';
else if(x1>x)cout<<1<<'\n';
else cout<<3<<'\n';
}else if(y1<y){
if(x1>=x)cout<<2<<'\n';
else cout<<3<<'\n';
}else{
if(x1==x)cout<<0<<'\n';
else if(x1>x)cout<<1<<'\n';
else cout<<3<<'\n';
}
}
else if(dir=='E'){
if(y1>y){
cout<<3<<'\n';
}else if(y1<y){
if(x1<x) cout<<2<<'\n';
else cout<<1<<'\n';
}else{
if(x1>=x)cout<<0<<'\n';
else cout<<2<<'\n';
}
}
else if(dir=='S'){
if(y1>y){
if(x1<=x)cout<<2<<'\n';
else if(x1>x)cout<<3<<'\n';
}else if(y1<y){
if(x1==x)cout<<0<<'\n';
else if(x1>x)cout<<3<<'\n';
else cout<<1<<'\n';
}else{
if(x1==x)cout<<0<<'\n';
else if(x1>x)cout<<3<<'\n';
else cout<<1<<'\n';
}
}
else {
if(y1>y){
if(x1==x)cout<<1<<'\n';
else if(x1>x)cout<<2<<'\n';
else cout<<1<<'\n';
}else if(y1<y){
cout<<3<<'\n';
}else{
if(x1<=x)cout<<0<<'\n';
else if(x1>x)cout<<2<<'\n';
}
}
}
return 0;
}