Language: C++

#include<iostream>
#include<queue>
#include<vector>

using namespace std;

class Puzzle{

public:
  vector<vector<int> > p;
  int lastorder;//1 ???  3?????? 5 ??????
  int ordernum;

  Puzzle(){
    this->p.resize(2);

    for(int i=0;i<2;i++){
      this->p[i].resize(4);
    }

    this->lastorder = 60;
    this->ordernum = 0;

  }

  Puzzle& operator=(const Puzzle& p1){
    for(int i=0;i<2;i++){
      for(int j=0;j<4;j++){
        this->p[i][j] = p1.p[i][j];
      }
    }
    this->lastorder = p1.lastorder;
    this->ordernum = p1.ordernum;
  }

  ~Puzzle(){

    vector<vector<int> >().swap(p);
  }

};

int main(){

  while(!cin.eof()){

    queue<Puzzle> q;

    Puzzle Start;

    for(int i=0;i < 2; i++){
      for(int j=0;j < 4; j++){
        cin >> Start.p[i][j];
      }
    }


    q.push(Start);

    while(1){

      Puzzle tmp;
      tmp = q.front();
      q.pop();

      bool ok = true;

      for(int i=0;i < 2; i++){
        for(int j=0;j < 4; j++){
          if(tmp.p[i][j] != (i*4 + j)){
            ok = false;
            break;
          }
        }
      }

      if(ok){
          cout << tmp.ordernum << endl;
          break;
      }

      int x,y;

      for(int i=0;i < 2; i++){
        for(int j=0;j < 4; j++){
          if(tmp.p[i][j] == 0){
            x = j;
            y = i;
          }
        }
      }

      tmp.ordernum++;

      Puzzle Beforetmp = tmp;

      //int beforeorder = tmp.lastorder;


      if(x != 3 && Beforetmp.lastorder != 3){
        swap(tmp.p[y][x],tmp.p[y][x+1]);
        tmp.lastorder = 1;
        q.push(tmp);
        tmp = Beforetmp;
      }

      if(x != 0 && Beforetmp.lastorder !=  1){
        swap(tmp.p[y][x],tmp.p[y][x-1]);
        tmp.lastorder = 3;
        q.push(tmp);
        tmp = Beforetmp;
      }

      if(Beforetmp.lastorder !=  5){
        swap(tmp.p[0][x],tmp.p[1][x]);
        tmp.lastorder = 5;
        q.push(tmp);
      }

      queue<Puzzle> empty;


    }
    swap(q, empty);

  }


    return 0;
}

Compiler output:
a.cc: In member function 'Puzzle& Puzzle::operator=(const Puzzle&)':
a.cc:34:3: warning: no return statement in function returning non-void [-Wreturn-type]
   33 |     this->ordernum = p1.ordernum;
  +++ |+  return *this;
   34 |   }
      |   ^
a.cc: In function 'int main()':
a.cc:124:9: error: no matching function for call to 'swap(std::queue<Puzzle>&, <unresolved overloaded function type>)'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/move.h:226:5: note: candidate: 'std::_Require<std::__not_<std::__is_tuple_like<_Tp> >, std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> > std::swap(_Tp&, _Tp&) [with _Tp = queue<Puzzle>; _Require<__not_<__is_tuple_like<_Tp> >, is_move_constructible<_Tp>, is_move_assignable<_Tp> > = void]'
  226 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/14/bits/move.h:226:25: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'std::queue<Puzzle>&'
  226 |     swap(_Tp& __a, _Tp& __b)
      |                    ~~~~~^~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h:445:5: note: candidate: 'typename std::enable_if<std::__is_swappable<_T2>::value>::type std::swap(queue<_Tp, _Seq>&, queue<_Tp, _Seq>&) [with _Tp = Puzzle; _Seq = deque<Puzzle, allocator<Puzzle> >; typename enable_if<__is_swappable<_T2>::value>::type = void]'
  445 |     swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_queue.h:445:51: note:   no known conversion for argument 2 from '<unresolved overloaded function type>' to 'std::queue<Puzzle>&'
  445 |     swap(queue<_Tp, _Seq>& __x, queue<_Tp, _Seq>& __y)
      |                                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/exception_ptr.h:229:5: note: candidate: 'void std::__exception_ptr::swap(exception_ptr&, exception_ptr&)'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
/usr/include/c++/14/bits/exception_ptr.h:229:25: note:   no known conversion for argument 1 from 'std::queue<Puzzle>' to 'std::__exception_ptr::exception_ptr&'
  229 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |          ~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/move.h:250:5: note: candidate: 'template<class _Tp, long unsigned int _Nm> std::__enable_if_t<((bool)std::__is_swappable<_Tp>::value)> std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])'
  250 |     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
      |     ^~~~
/usr/include/c++/14/bits/move.h:250:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   mismatched types '_Tp [_Nm]' and 'std::queue<Puzzle>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/bits/stl_pair.h:1089:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)'
 1089 |     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1089:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::pair<_T1, _T2>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note: candidate: 'template<class _T1, class _T2> typename std::enable_if<(! std::__and_<std::__is_swappable<_T1>, std::__is_swappable<_T2> >::value)>::type std::swap(pair<_T1, _T2>&, pair<_T1, _T2>&)' (deleted)
 1106 |     swap(pair<_T1, _T2>&, pair<_T1, _T2>&) = delete;
      |     ^~~~
/usr/include/c++/14/bits/stl_pair.h:1106:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::pair<_T1, _T2>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:4039:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> void std::swap(__cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 4039 |     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~
/usr/include/c++/14/bits/basic_string.h:4039:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:47,
                 from /usr/include/c++/14/string:68:
/usr/include/c++/14/tuple:2805:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<std::__and_<std::__is_swappable<_Elements>...>::value>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)'
 2805 |     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
      |     ^~~~
/usr/include/c++/14/tuple:2805:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::tuple<_UTypes ...>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
/usr/include/c++/14/tuple:2823:5: note: candidate: 'template<class ... _Elements> typename std::enable_if<(! std::__and_<std::__is_swappable<_Elements>...>::value)>::type std::swap(tuple<_UTypes ...>&, tuple<_UTypes ...>&)' (deleted)
 2823 |     swap(tuple<_Elements...>&, tuple<_Elements...>&) = delete;
      |     ^~~~
/usr/include/c++/14/tuple:2823:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::tuple<_UTypes ...>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/c++/14/queue:62:
/usr/include/c++/14/bits/stl_deque.h:2370:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(deque<_Tp, _Alloc>&, deque<_Tp, _Alloc>&)'
 2370 |     swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_deque.h:2370:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::deque<_Tp, _Alloc>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63:
/usr/include/c++/14/bits/stl_vector.h:2122:5: note: candidate: 'template<class _Tp, class _Alloc> void std::swap(vector<_Tp, _Alloc>&, vector<_Tp, _Alloc>&)'
 2122 |     swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
      |     ^~~~
/usr/include/c++/14/bits/stl_vector.h:2122:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::vector<_Tp, _Alloc>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:834:5: note: candidate: 'template<class _Tp, class _Sequence, class _Compare> typename std::enable_if<std::__and_<std::__is_swappable<_T2>, std::__is_swappable<_Compare> >::value>::type std::swap(priority_queue<_Tp, _Sequence, _Compare>&, priority_queue<_Tp, _Sequence, _Compare>&)'
  834 |     swap(priority_queue<_Tp, _Sequence, _Compare>& __x,
      |     ^~~~
/usr/include/c++/14/bits/stl_queue.h:834:5: note:   template argument deduction/substitution failed:
a.cc:124:9: note:   'std::queue<Puzzle>' is not derived from 'std::priority_queue<_Tp, _Sequence, _Compare>'
  124 |     swap(q, empty);
      |     ~~~~^~~~~~~~~~