-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11831.cpp
More file actions
executable file
·104 lines (90 loc) · 2.41 KB
/
11831.cpp
File metadata and controls
executable file
·104 lines (90 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
using namespace std;
int main()
{
int dir;
while(true)
{
int n,m,t;
int ans=0;
cin>>n>>m>>t;
if(n==0 && m==0 && t==0)break;
char arr[n][m];
int p,q;
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
cin>>arr[i][j];
char c=arr[i][j];
if(c=='N'|| c=='S' || c=='L' || c=='O')
{
p=i;
q=j;
if(c=='N')dir=0;
if(c=='L')dir=1;
if(c=='S')dir=2;
if(c=='O')dir=3;
}
}
}
char temp[t];
int check=0;
for(int i=0; i<t; i++)
cin>>temp[i];
for(int i=0; i<t; i++){
if(temp[i]=='D')
{
dir++;
dir=dir%4;
}
if(temp[i]=='E')
{
dir--;
if(dir<0)
dir=(dir+4)%4;
}
if(temp[i]=='F')
{
if(p-1>=0 && arr[p-1][q]!='#'&& dir==0)
{
if(arr[p-1][q]=='*')
{
ans++;
arr[p-1][q]='.';
}
p--;
}
else if(dir==1 && q+1<=(m-1) && arr[p][q+1]!='#')
{
q++;
if(arr[p][q]=='*')
{
ans++;
arr[p][q]='.';
}
}
else if(dir==2 && p+1<=(n-1) && arr[p+1][q]!='#')
{
p++;
if(arr[p][q]=='*')
{
ans++;
arr[p][q]='.';
}
}
else if(dir==3 && q-1>=0 && arr[p][q-1]!='#')
{
q--;
if(arr[p][q]=='*')
{
ans++;
arr[p][q]='.';
}
}
}
}
cout<<ans<<endl;
}
return 0;
}