Language: C++

#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;
typedef pair<string, int> P;

int iti;
string n;

void solve(){
	queue<P> que;
	map<string, int> m;
	map<string, int>::iterator ite;
	que.push(P(n, 0));
	m.insert(make_pair(n, 0));
	while(true){
		P p = que.front(); que.pop();
		if(p.first == "01234567"){
			cout << p.second << endl;
			break;
		}
		for(int i = 0; i < 8; i++){
			if(p.first[i] == '0') iti = i;
		}
		if(iti != 3 && iti != 7){
			swap(p.first[iti], p.first[iti+1]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti], p.first[iti+1]);
		}
		if(iti != 0 && iti != 4){
			swap(p.first[iti], p.first[iti-1]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti], p.first[iti-1]);
		}
		if(iti <= 3){
			swap(p.first[iti+4], p.first[iti]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti+4], p.first[iti]);
		}
		else{
			swap(p.first[iti-4], p.first[iti]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti-4], p.first[iti]);
		}
	}
}

int main(){
	char trash;
	while(cin >> trash){
		n.push_back(trash);
		for(int i = 1; i < 8; i++){ 
			cin >> trash;
			n.push_back(trash);
		}
		solve();
		n.clear();
	}
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:14:9: error: 'queue' was not declared in this scope
   14 |         queue<P> que;
      |         ^~~~~
a.cc:7:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
    6 | #include <cstring>
  +++ |+#include <queue>
    7 | using namespace std;
a.cc:14:16: error: expected primary-expression before '>' token
   14 |         queue<P> que;
      |                ^
a.cc:14:18: error: 'que' was not declared in this scope
   14 |         queue<P> que;
      |                  ^~~
a.cc:15:9: error: 'map' was not declared in this scope
   15 |         map<string, int> m;
      |         ^~~
a.cc:7:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    6 | #include <cstring>
  +++ |+#include <map>
    7 | using namespace std;
a.cc:15:19: error: expected primary-expression before ',' token
   15 |         map<string, int> m;
      |                   ^
a.cc:15:21: error: expected primary-expression before 'int'
   15 |         map<string, int> m;
      |                     ^~~
a.cc:16:19: error: expected primary-expression before ',' token
   16 |         map<string, int>::iterator ite;
      |                   ^
a.cc:16:21: error: expected primary-expression before 'int'
   16 |         map<string, int>::iterator ite;
      |                     ^~~
a.cc:18:9: error: 'm' was not declared in this scope; did you mean 'tm'?
   18 |         m.insert(make_pair(n, 0));
      |         ^
      |         tm
a.cc:22:25: error: 'cout' was not declared in this scope
   22 |                         cout << p.second << endl;
      |                         ^~~~
a.cc:7:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    6 | #include <cstring>
  +++ |+#include <iostream>
    7 | using namespace std;
a.cc:30:25: error: 'ite' was not declared in this scope; did you mean 'iti'?
   30 |                         ite = m.find(p.first);
      |                         ^~~
      |                         iti
a.cc:39:25: error: 'ite' was not declared in this scope; did you mean 'iti'?
   39 |                         ite = m.find(p.first);
      |                         ^~~
      |                         iti
a.cc:48:25: error: 'ite' was not declared in this scope; did you mean 'iti'?
   48 |                         ite = m.find(p.first);
      |                         ^~~
      |                         iti
a.cc:57:25: error: 'ite' was not declared in this scope; did you mean 'iti'?
   57 |                         ite = m.find(p.first);
      |                         ^~~
      |                         iti
a.cc: In function 'int main()':
a.cc:69:15: error: 'cin' was not declared in this scope
   69 |         while(cin >> trash){
      |               ^~~
a.cc:69:15: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'