20分求助
查看原帖
20分求助
356806
ink!sans楼主2020/11/5 20:22

样例都过了```c #include #include #include using namespace std; int T,x1,x2,y1,y2,ans=0; char a[55]; int main(){ cin>>x1>>x2; cin>>y1>>y2; cin>>T; for(int i=0;i<T;i++){ cin>>a[i]; } if(x1==y1&&x2==y2) cout<<0; for(int i=0;i<T;i++){ if(x1!=y1&&x2==y2){ if(x1>y1){ if(a[i]=='W'){ x1--; ans++; } else ans++; } if(x1<y1){ if(a[i]=='E'){ x1++; ans++; } else ans++; } if(x1==y1) break; } else if(x1==y1&&x2!=y2){ if(x2>y2){ if(a[i]=='S'){ x2--; ans++; } else ans++; } if(x2<y2){ if(a[i]=='N'){ x2++; ans++; } else ans++; } if(x2==y2) break; } else if(x1!=y1&&x2!=y2){ if(x1>y1&&x2>y2){ if(a[i]=='W'){ x1--; ans++; } else if(a[i]=='S'){ x2--; ans++; } else ans++; } else if(x1>y1&&x2<y2){ if(a[i]=='W'){ x1--; ans++; } else if(a[i]=='N'){ x2++; ans++; } else ans++; } else if(x1<y1&&x2>y2){ if(a[i]=='E'){ x1++; ans++; } else if(a[i]=='S'){ x2--; ans++; } else ans++; } else if(x1<y1&&x2<y2){ if(a[i]=='E'){ x1++; ans++; } else if(a[i]=='N'){ x2++; ans++; } else ans++; } else if(x1==y1&&x2==y2) break; } } if(x1==y1&&x2==y2) cout<<ans; else cout<<-1; return 0; }

2020/11/5 20:22
加载中...