Language: C++

#include<iostream>
#include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
int mp[1002][1002],mp2[1002][1002];
int main()
{
????????char a;
????????int t, j, h, w, k, i;
????????pair<int, int> s, m[10];
????????queue<pair<int, int> > u;
????????queue<int> e;
????????cin >> h >> w >> k;
????????for (i = 0; i <= h; i++)
????????{
????????????????mp[i][0] = 1;
????????????????mp[i][w + 1] = 1;
????????????????mp2[i][0] = 1;
????????????????mp2[i][w + 1] = 1;
??
????????}
????????for (i = 0; i <= w; i++)
????????{
????????????????mp[0][i] = 1;
????????????????mp[h + 1][i] = 1;
????????????????mp2[0][i] = 1;
????????????????mp2[h + 1][i] = 1;
????????}
????????for (i = 1; i <= h; i++)
????????{
????????????????for (j = 1; j <= w; j++)
????????????????{
????????????????????????cin >> a;
????????????????????????if (a == 'X')
????????????????????????{
????????????????????????????????mp[i][j] = 1;
????????????????????????}
????????????????????????if (a == 'S')
????????????????????????{
????????????????????????????????mp[i][j] = 10;
????????????????????????????????s.first = i;
????????????????????????????????s.second = j;
????????????????????????}
????????????????????????if (a == '1')
????????????????????????{
????????????????????????????????mp[i][j] = 11;
????????????????????????????????m[1].first = i;
????????????????????????????????m[1].second = j;
????????????????????????}
????????????????????????if (a == '2')
????????????????????????{
????????????????????????????????mp[i][j] = 12;
????????????????????????????????m[2].first = i;
????????????????????????????????m[2].second = j;
????????????????????????}
????????????????????????if (a == '3')
????????????????????????{
????????????????????????????????mp[i][j] = 13;
????????????????????????????????m[3].first = i;
????????????????????????????????m[3].second = j;
????????????????????????}
????????????????????????if (a == '4')
????????????????????????{
????????????????????????????????mp[i][j] = 14;
????????????????????????????????m[4].first = i;
????????????????????????????????m[4].second = j;
????????????????????????}
????????????????????????if (a == '5')
????????????????????????{
????????????????????????????????mp[i][j] = 15;
????????????????????????????????m[5].first = i;
????????????????????????????????m[5].second = j;
????????????????????????}
????????????????????????if (a == '6')
????????????????????????{
????????????????????????????????mp[i][j] = 16;
????????????????????????????????m[6].first = i;
????????????????????????????????m[6].second = j;
????????????????????????}
????????????????????????if (a == '7')
????????????????????????{
????????????????????????????????mp[i][j] = 17;
????????????????????????????????m[7].first = i;
????????????????????????????????m[7].second = j;
????????????????????????}
????????????????????????if (a == '8')
????????????????????????{
????????????????????????????????mp[i][j] = 18;
????????????????????????????????m[8].first = i;
????????????????????????????????m[8].second = j;
????????????????????????}
????????????????????????if (a == '9')
????????????????????????{
????????????????????????????????mp[i][j] = 19;
????????????????????????????????m[9].first = i;
????????????????????????????????m[9].second = j;
????????????????????????}
????????????????}
????????}
????????t = 0;
????????e.push(0);
????????i = 1;
????????u.push(s);
????????while (i <= k)
????????{
????????????????t = e.front();
????????????????e.pop();
????????????????s = u.front();
????????????????u.pop();
????????????????if (s == m[i])
????????????????{
????????????????????????i++;
????????????????????????memset(mp2, 0, sizeof(mp2));
????????????????????????while (!u.empty())
????????????????????????{
????????????????????????????????u.pop();
????????????????????????}
????????????????????????while (!e.empty())
????????????????????????{
????????????????????????????????e.pop();
????????????????????????}
????????????????????????e.push(t);
????????????????????????u.push(s);
????????????????????????continue;
????????????????}
????????????????if (mp[s.first + 1][s.second] != 1 && mp2[s.first + 1][s.second] != 1)
????????????????{
????????????????????????mp2[s.first + 1][s.second] = 1;
????????????????????????s.first++;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.first--;
????????????????}
????????????????if (mp[s.first][s.second + 1] != 1 && mp2[s.first][s.second + 1] != 1)
????????????????{
????????????????????????mp2[s.first][s.second + 1] = 1;
????????????????????????s.second++;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.second--;
????????????????}
????????????????if (mp[s.first - 1][s.second] != 1 && mp2[s.first - 1][s.second] != 1)
????????????????{
????????????????????????mp2[s.first - 1][s.second] = 1;
????????????????????????s.first--;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.first++;
????????????????}
????????????????if (mp[s.first][s.second - 1] != 1 && mp2[s.first][s.second - 1] != 1)
????????????????{
????????????????????????mp2[s.first][s.second - 1] = 1;
????????????????????????s.second--;
????????????????????????u.push(s);
????????????????????????t++;
????????????????????????e.push(t);
????????????????????????t--;
????????????????????????s.second++;
????????????????}
????????}
????????cout << t << endl;
????????return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:9:1: error: expected primary-expression before '?' token
    9 | ????????char a;
      | ^
a.cc:9:2: error: expected primary-expression before '?' token
    9 | ????????char a;
      |  ^
a.cc:9:3: error: expected primary-expression before '?' token
    9 | ????????char a;
      |   ^
a.cc:9:4: error: expected primary-expression before '?' token
    9 | ????????char a;
      |    ^
a.cc:9:5: error: expected primary-expression before '?' token
    9 | ????????char a;
      |     ^
a.cc:9:6: error: expected primary-expression before '?' token
    9 | ????????char a;
      |      ^
a.cc:9:7: error: expected primary-expression before '?' token
    9 | ????????char a;
      |       ^
a.cc:9:8: error: expected primary-expression before '?' token
    9 | ????????char a;
      |        ^
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:9:9: error: expected ':' before 'char'
    9 | ????????char a;
      |         ^~~~
      |         :
a.cc:9:9: error: expected primary-expression before 'char'
    9 | ????????char a;
      |         ^~~~
a.cc:10:1: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      | ^
a.cc:10:2: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |  ^
a.cc:10:3: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |   ^
a.cc:10:4: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |    ^
a.cc:10:5: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |     ^
a.cc:10:6: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |      ^
a.cc:10:7: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |       ^
a.cc:10:8: error: expected primary-expression before '?' token
   10 | ????????int t, j, h, w, k, i;
      |        ^
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:10:9: error: expected ':' before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
      |         :
a.cc:10:9: error: expected primary-expression before 'int'
   10 | ????????int t, j, h, w, k, i;
      |         ^~~
a.cc:11:1: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      | ^
a.cc:11:2: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |  ^
a.cc:11:3: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |   ^
a.cc:11:4: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |    ^
a.cc:11:5: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |     ^
a.cc:11:6: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |      ^
a.cc:11:7: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |       ^
a.cc:11:8: error: expected primary-expression before '?' token
   11 | ????????pair<int, int> s, m[10];
      |        ^
a.cc:11:24: error: expected primary-expression before 's'
   11 | ????????pair<int, int> s, m[10];
      |                        ^
a.cc:11:23: error: expected ':' before 's'
   11 | ????????pair<int, int> s, m[10];
      |                       ^~
      |                       :
a.cc:11:24: error: 's' was not declared in this scope
   11 | ????????pair<int, int> s, m[10];
      |                        ^
a.cc:11:27: error: 'm' was not declared in this scope; did you mean 'tm'?
   11 | ????????pair<int, int> s, m[10];
      |                           ^
      |                           tm
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:11:32: error: expected ':' before ';' token
   11 | ????????pair<int, int> s, m[10];
      |                                ^
      |                                :
a.cc:11:32: error: expected primary-expression before ';' token
a.cc:12:1: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      | ^
a.cc:12:2: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |  ^
a.cc:12:3: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |   ^
a.cc:12:4: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |    ^
a.cc:12:5: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |     ^
a.cc:12:6: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |      ^
a.cc:12:7: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |       ^
a.cc:12:8: error: expected primary-expression before '?' token
   12 | ????????queue<pair<int, int> > u;
      |        ^
a.cc:12:32: error: expected primary-expression before 'u'
   12 | ????????queue<pair<int, int> > u;
      |                                ^
a.cc:12:31: error: expected ':' before 'u'
   12 | ????????queue<pair<int, int> > u;
      |                               ^~
      |                               :
a.cc:12:32: error: 'u' was not declared in this scope
   12 | ????????queue<pair<int, int> > u;
      |                                ^
a.cc:12:33: error: expected ':' before ';' token
   12 | ????????queue<pair<int, int> > u;
      |