Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define set(x,y) memset(x,y,sizeof(x))
#define scan(x) scanf("%d",&x)
#define For(x,y,z)  for(int x=y;x<=z;x++)
using namespace std;
const int MAXN = 210;
int maps[202][202];
int fx,fy;
int stx,sty;
bool vis[MAXN][MAXN];
bool visited[202][202];
int index;
int dis[MAXN][MAXN];
pair<int, int > a[4004];

typedef struct Node{
int x,y,step;
Node(int xx,int yy,int ss):x(xx),y(yy),step(ss){};
}Node;
 int m,n;
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int BFS(int Stx,int Sty)
{
    queue<Node>q;
    set(vis,0);

    q.push(Node(Stx,Sty,0));
    vis[Stx][Sty]=1;
    while(!q.empty())
    {
       Node s=q.front();

        if(s.x==fx&&s.y==fy)
            return s.step;
        for(int i=0;i<4;i++)
        {
            int x=s.x+dir[i][0];
            int y=s.y+dir[i][1];
            if(x>=1&&x<=m&&y>=1&&y<=n&&(!maps[x][y]))
            {
                q.push(Node(x,y,s.step+1));
                vis[x][y]=1;
            }
        }
        q.pop();
    }
    return -1;
}
int main()
{

    cin>>m>>n;
    char s[205];
    for(int i=1;i<=m;i++)
    {
        cin>>s;
        for(int j=0;j<n;j++)
        {
            if(s[j]=='.')
                maps[i][j+1]=0;
            else if(s[j]=='#')
                maps[i][j+1]=1;
            else if(s[j]=='%')
            {
                fx=i;
                fy=j+1;
            }
            else if(s[j]=='@')
            {
                stx=i;
                sty=j+1;

            }
            else if(s[j]=='$')
            {
                index++;
                 maps[i][j+1]=1;
                a[index].first=i;
                a[index].second=j+1;

            }
        }
    }
    int maxn=BFS(stx,sty);
   //cout<<"公主的最短路"<<maxn<<endl;
    int ans=99999;
    for(int i=1;i<=index;i++)
    {
        ans=min(ans,BFS(a[i].first,a[i].second));
    }
    if(ans>maxn&&maxn>=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Compiler output:
a.cc:18:5: error: 'int index' redeclared as different kind of entity
   18 | int index;
      |     ^~~~~
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from a.cc:2:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:82:22: error: no post-increment operator for type
   82 |                 index++;
      |                      ^~
a.cc:84:18: error: invalid types 'std::pair<int, int> [4004][<unresolved overloaded function type>]' for array subscript
   84 |                 a[index].first=i;
      |                  ^
a.cc:85:18: error: invalid types 'std::pair<int, int> [4004][<unresolved overloaded function type>]' for array subscript
   85 |                 a[index].second=j+1;
      |                  ^
a.cc:93:18: error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<='
   93 |     for(int i=1;i<=index;i++)
      |                 ~^~~~~~~