Language: C++

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>

using namespace std;

char visited[0xffffff];

inline int is_visited(unsigned s){ return visited[s&0xffffff]; }
inline void set_visited(unsigned s){ visited[s&0xffffff]=1; }

inline unsigned exchange(unsigned s, unsigned p1, unsigned p2, unsigned n){

    unsigned x  = ((s>>p1)^(s>>p2))&((1U<<n)-1);
    unsigned ns = s^((x<<p1)|(x<<p2));

    return ns;

}

int main(){

    cin.sync_with_stdin(false);

    unsigned int a[8];

    unsigned f_state = 0;
    
    for(int i=0;i<8;++i) f_state |= (i<<(3*i));

    while(cin >> a[0]){

        for(int i=1;i<8;++i) cin >> a[i];

        unsigned istate=0;

        for(int i=0;i<8;++i)istate |= (a[i]<<(3*i));

        for(int i=0;i<8;++i){
            if(a[i]==0){
                istate |= (i<<24);
            }
        }

        queue<unsigned> q;
        q.push(istate);

        memset(visited,0,sizeof(visited));
        set_visited(istate);

        int flag = 0;

        for(int n=0;;++n){

            queue<unsigned> nq;

            while(!q.empty()){

                unsigned p = q.front(); q.pop();
                unsigned state = (p&0xffffff);
                unsigned pos = (p>>24);

                if(state == f_state){ flag=1; cout << n << endl; break; }

                int bit_pos = 3*pos;
                unsigned next_state;

                if(pos!=0 && pos!=4){

                    next_state = exchange(state,bit_pos,bit_pos-3,3);
                    next_state |= ((pos-1)<<24);

                    if(!is_visited(next_state)){
                        set_visited(next_state);
                        nq.push(next_state);
                    }

                }

                if(pos!=3 && pos!=7){

                    next_state = exchange(state,bit_pos,bit_pos+3,3);
                    next_state |= ((pos+1)<<24);

                    if(!is_visited(next_state)){
                        set_visited(next_state);
                        nq.push(next_state);
                    }

                }

                if(pos<=3){

                    next_state = exchange(state,bit_pos,bit_pos+12,3);
                    next_state |= ((pos+4)<<24);

                    if(!is_visited(next_state)){
                        set_visited(next_state);
                        nq.push(next_state);
                    }

                }
               
                if(pos>=4){

                    next_state = exchange(state,bit_pos,bit_pos-12,3);
                    next_state |= ((pos-4)<<24);

                    if(!is_visited(next_state)){
                        set_visited(next_state);
                        nq.push(next_state);
                    }

                }

            }

            if(flag)break;

            q = nq;

        }

    }

    return 0;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:27:9: error: 'std::istream' {aka 'class std::basic_istream<char>'} has no member named 'sync_with_stdin'; did you mean 'sync_with_stdio'?
   27 |     cin.sync_with_stdin(false);
      |         ^~~~~~~~~~~~~~~
      |         sync_with_stdio