Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <set>
using namespace std;
class pz{
public:
  int a,b,c,d,e,f,g,h;
  bool operator < (const pz& a) const{
    if(a.a != this->a) return a.a > this->a;
    else if(a.b != this->b) return a.b > this->b;
    else if(a.c != this->c) return a.c > this->c;
    else if(a.d != this->d) return a.d > this->d;
    else if(a.e != this->e) return a.e > this->e;
    else if(a.f != this->f) return a.f > this->f;
    else if(a.g != this->g) return a.g > this->g;
    else return false;
  }
  bool operator == (const pz& a) const{
    return a.a == this->a && a.b == this.b && a.c == this->c && a.d == this->d
      && a.e == this->e && a.f == this->f && a.g == this->g && a.h == this->h;
  }
};
#define P pair<pz,int>
void swap(int* a,int* b)
{
  int t;
  t = *a;
  *a = *b;
  *b = t;
}
int main()
{
  pz a;
  while(cin >> a.a >> a.b >> a.c >> a.d >> a.e >> a.f >> a.g >> a.h){
    queue< P > q;
    set< pz > st;
    q.push( P(a,0) );
    while(!q.empty()){
      P v = q.front(); q.pop();
      pz p = v.first;
      if(p.a == 0 && p.b == 1 && p.c == 2 && p.d == 3 &&
	 p.e == 4 && p.f == 5 && p.g == 6 && p.h == 7){
	cout << v.second << endl;
	break;
      }
      if(p.a == 0){
	pz s = p;
	swap(&s.a,&s.b);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.a,&t.e);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(s);
	}
      }else if(p.b == 0){
	pz s = p;
	swap(&s.b,&s.a);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.b,&t.c);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
	pz u = p;
	swap(&u.b,&u.f);
	if(st.find(u) == st.end()){
	  q.push( P(u,v.second+1) );
	  st.insert(u);
	}
      }else if(p.c == 0){
	pz s = p;
	swap(&s.c,&s.b);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.c,&t.d);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
	pz u = p;
	swap(&u.c,&u.g);
	if(st.find(u) == st.end()){
	  q.push( P(u,v.second+1) );
	  st.insert(u);
	}
      }else if(p.d == 0){
	pz s = p;
	swap(&s.d,&s.c);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.d,&t.h);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
      }else if(p.e == 0){
	pz s = p;
	swap(&s.e,&s.f);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.e,&t.a);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
      }else if(p.f == 0){
	pz s = p;
	swap(&s.f,&s.e);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.f,&t.g);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
	pz u = p;
	swap(&u.f,&u.b);
	if(st.find(u) == st.end()){
	  q.push( P(u,v.second+1) );
	  st.insert(u);
	}
      }else if(p.g == 0){
	pz s = p;
	swap(&s.g,&s.f);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.g,&t.h);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
	pz u = p;
	swap(&u.g,&u.c);
	if(st.find(u) == st.end()){
	  q.push( P(u,v.second+1) );
	  st.insert(u);
	}
      }else if(p.h == 0){
	pz s = p;
	swap(&s.h,&s.g);
	if(st.find(s) == st.end()){
	  q.push( P(s,v.second+1) );
	  st.insert(s);
	}
	pz t = p;
	swap(&t.h,&t.d);
	if(st.find(t) == st.end()){
	  q.push( P(t,v.second+1) );
	  st.insert(t);
	}
      }
    }
  }
  return 0;
}

Compiler output:
a.cc: In member function 'bool pz::operator==(const pz&) const':
a.cc:20:42: error: request for member 'b' in '(const pz*)this', which is of pointer type 'const pz*' (maybe you meant to use '->' ?)
   20 |     return a.a == this->a && a.b == this.b && a.c == this->c && a.d == this->d
      |                                          ^