Language: C++

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
#define MAXN 363000  //9!==326880
struct node
{
    int s[9];
    int a;
    int b;
    int step;
};
int fac[10]= {1,1,2,6,24,120,720,5040,40320,362880};//分别存储1--9的阶乘值
int dir[4][2]= {-1,0,1,0,0,-1,0,1};
int aim=322561;//123456780对应的hash值
bool vis[MAXN];
node str,now,next
int cantor(const int *s)
{
    int sum=0;
    for(int i=0; i<9; i++)
    {
        int num=0;
        for(int j=0; j<i; j++)
            if(s[j]>s[i])
                num++;
        sum+=(num*fac[i]);
    }
    return (sum+1);
}
bool bfs()
{
    memset(vis,0,sizeof(vis));
    queue<node>q;
    q.push(str);
    vis[str.b]=1;
    while(!q.empty())
    {
        now=q.front();
        q.pop();
        int x=now.a/3;
        int y=now.a%3;
        for(int i=0; i<4; i++)
        {
            int tx=x+dir[i][0],ty=y+dir[i][1];
            if(tx<0||tx>=3||ty<0||ty>=3)
                continue;
            next=now;
            next.a=tx*3+ty;
            next.s[now.a]=next.s[next.a];
            next.s[next.a]=0;
            next.b=cantor(next.s);
            if(!vis[next.b])
            {
                vis[next.b]=1;
                if(next.b==aim)
                {
                    return true;
                }
                next.step=now.step+1;
                q.push(next);
            }
        }
    }
    return 0;
}
char sss[3];
int main()
{
    char q[10];
    for(int i=0; i<9; i++)
    {
        scanf("%s",sss);
        q[i]=sss[0];
    }
    int len=strlen(q);
    int num=0;
    for(int i=0; i<len; i++)
    {
        if(q[i]>='1'&&q[i]<='9')
        {
            str.s[num++]=q[i]-'0';
        }
        else if(q[i]=='0')
        {
            str.s[num]=0;
            str.a=num++;
        }
    }
    str.b=cantor(str.s);
    if(str.b==aim)
        printf("%d\n",0);
    else if(bfs())
        printf("%d\n",next.step+1);
    return 0;
}


Compiler output:
a.cc:18:1: error: expected initializer before 'int'
   18 | int cantor(const int *s)
      | ^~~
a.cc: In function 'bool bfs()':
a.cc:48:18: error: overloaded function with no contextual type information
   48 |             next=now;
      |                  ^~~
a.cc:49:18: error: overloaded function with no contextual type information
   49 |             next.a=tx*3+ty;
      |                  ^
a.cc:50:18: error: overloaded function with no contextual type information
   50 |             next.s[now.a]=next.s[next.a];
      |                  ^
a.cc:50:32: error: overloaded function with no contextual type information
   50 |             next.s[now.a]=next.s[next.a];
      |                                ^
a.cc:50:39: error: overloaded function with no contextual type information
   50 |             next.s[now.a]=next.s[next.a];
      |                                       ^
a.cc:51:18: error: overloaded function with no contextual type information
   51 |             next.s[next.a]=0;
      |                  ^
a.cc:51:25: error: overloaded function with no contextual type information
   51 |             next.s[next.a]=0;
      |                         ^
a.cc:52:18: error: overloaded function with no contextual type information
   52 |             next.b=cantor(next.s);
      |                  ^
a.cc:52:32: error: overloaded function with no contextual type information
   52 |             next.b=cantor(next.s);
      |                                ^
a.cc:52:20: error: 'cantor' was not declared in this scope
   52 |             next.b=cantor(next.s);
      |                    ^~~~~~
a.cc:53:26: error: overloaded function with no contextual type information
   53 |             if(!vis[next.b])
      |                          ^
a.cc:55:26: error: overloaded function with no contextual type information
   55 |                 vis[next.b]=1;
      |                          ^
a.cc:56:25: error: overloaded function with no contextual type information
   56 |                 if(next.b==aim)
      |                         ^
a.cc:60:22: error: overloaded function with no contextual type information
   60 |                 next.step=now.step+1;
      |                      ^~~~
a.cc:61:23: error: no matching function for call to 'std::queue<node>::push(<unresolved overloaded function type>)'
   61 |                 q.push(next);
      |                 ~~~~~~^~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = node; _Sequence = std::deque<node, std::allocator<node> >; value_type = node]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::queue<node>::value_type&' {aka 'const node&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = node; _Sequence = std::deque<node, std::allocator<node> >; value_type = node]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::queue<node>::value_type&&' {aka 'node&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:90:11: error: 'cantor' was not declared in this scope
   90 |     str.b=cantor(str.s);
      |           ^~~~~~
a.cc:94:28: error: overloaded function with no contextual type information
   94 |         printf("%d\n",next.step+1);
      |                            ^~~~