This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
char A[n][m];
int stx, sty;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
cin >> A[i][j];
if(A[i][j] == 'o')
{
stx = i;
sty = j;
}
}
}
vector <int> dx, dy;
vector <char> vec;
dx = {0, -1, 1, 0};
dy = {1, 0, 0, -1};
vec = {'E', 'N', 'S', 'W'};
vector <char> vec1;
vec1 = {'>', '^', 'v', '<'};
char p1 = ' ';
int ans = 1e9;
for(int i = 0; i < 4; i++)
{
pair <int, int> st = {stx + dx[i], sty + dy[i]};
bool fl = 0;
int cnt = 0;
while(true)
{
cnt++;
if(st.first < 0 || st.second < 0 || st.first >= n || st.second >= m)
{
break;
}
if(A[st.first][st.second] == 'x')
{
fl = 1;
break;
}
if(A[st.first][st.second] == '.')
{
break;
}
for(int j = 0; j < 4; j++)
{
if(A[st.first][st.second] == vec1[j])
{
st.first += dx[j];
st.second += dy[j];
break;
}
}
}
// cout << st.first << " " << st.second << "\n";
if(fl && cnt < ans)
{
ans = cnt;
p1 = vec[i];
}
}
if(p1 == ' ')
{
cout << ":(";
}
else
{
cout << ":)\n";
cout << p1;
}
return 0;
}
Compilation message (stderr)
patkice.cpp: In function 'int main()':
patkice.cpp:35:35: warning: 'stx' may be used uninitialized in this function [-Wmaybe-uninitialized]
35 | pair <int, int> st = {stx + dx[i], sty + dy[i]};
patkice.cpp:35:48: warning: 'sty' may be used uninitialized in this function [-Wmaybe-uninitialized]
35 | pair <int, int> st = {stx + dx[i], sty + dy[i]};
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |