社区讨论
40分!
P2689东南西北参与者 3已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lwar9g54
- 此快照首次捕获于
- 2024/05/17 22:08 2 年前
- 此快照最后确认于
- 2024/05/18 08:32 2 年前
CPP
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j;
int x,y;
cin>>i>>j;
cin>>x>>y;
int t;
cin>>t;
int ans=0;
while(t--)
{
char ch;
cin>>ch;
ans++;
if(ch=='N'&&i<x) i++;
if(ch=='S'&&i>x) i--;
if(ch=='E'&&j<y) j++;
if(ch=='W'&&j>y) j--;
if(i==x&&j==y)
{
cout<<ans;
return 0;
}
}
cout<<-1;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...