Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
 
map<string, int> dp;
int direction[4] = { 1, -1, 4, -4 };
 
//************************************
// Method:    bfs
// FullName:  bfs
// Access:    public 
// Returns:   void
// Qualifier: 隶ゥ0貍ォ貂ク謨エ荳ェ蟄嶺クイ
//************************************
void bfs()
{
    queue<string> que;
    que.push("01234567");
    dp["01234567"] = 0;
    while (!que.empty())
    {
        string now = que.front(); que.pop();
        // p譏ッ'0'逧?ス咲スョ
        int p = 0;
        for (int j = 0; j < 8; ++j)
        {
            if (now[j] == '0')
            {
                p = j;
                break;
            }
        }
 
        for (int i = 0; i < 4; ++i)
        {
            int n = p + direction[i];
            if (0 <= n && n < 8 && 
                !(p == 3 && i == 0) && // 蜿ウ荳願ァ剃ク崎?蜀榊セ?承莠?                !(p == 4 && i == 1))   // 蟾ヲ荳玖ァ剃ク崎?蜀榊セ?キヲ莠?            {
                string next = now;
                swap(next[p], next[n]);
                if (dp.find(next) == dp.end())
                {
                    dp[next] = dp[now] + 1;
                    que.push(next);
                }
            }
        }
    }
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
    bfs();
    string line;
    while (getline(cin, line))
    {
        line.erase(remove(line.begin(), line.end(), ' '), line.end());
        cout << dp[line] << endl;
    }
 
    return 0;
}

Compiler output:
a.cc: In function 'void bfs()':
a.cc:42:24: error: expected primary-expression before 'next'
   42 |                 string next = now;
      |                        ^~~~
a.cc:43:26: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |                 swap(next[p], next[n]);
      |                          ^
a.cc:43:35: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   43 |                 swap(next[p], next[n]);
      |                                   ^
a.cc:43:39: error: expected ')' before ';' token
   43 |                 swap(next[p], next[n]);
      |                                       ^
      |                                       )
a.cc:40:16: note: to match this '('
   40 |             if (0 <= n && n < 8 &&
      |                ^
a.cc:44:28: error: no matching function for call to 'std::map<std::__cxx11::basic_string<char>, int>::find(<unresolved overloaded function type>)'
   44 |                 if (dp.find(next) == dp.end())
      |                     ~~~~~~~^~~~~~
In file included from /usr/include/c++/14/map:63,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_map.h:1224:9: note: candidate: 'template<class _Kt> decltype (((std::map<_Key, _Tp, _Compare, _Alloc>*)this)->std::map<_Key, _Tp, _Compare, _Alloc>::_M_t._M_find_tr(__x)) std::map<_Key, _Tp, _Compare, _Alloc>::find(const _Kt&) [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >]'
 1224 |         find(const _Kt& __x) -> decltype(_M_t._M_find_tr(__x))
      |         ^~~~
/usr/include/c++/14/bits/stl_map.h:1224:9: note:   template argument deduction/substitution failed:
a.cc:44:28: note:   couldn't deduce template parameter '_Kt'
   44 |                 if (dp.find(next) == dp.end())
      |                     ~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_map.h:1249:9: note: candidate: 'template<class _Kt> decltype (((const std::map<_Key, _Tp, _Compare, _Alloc>*)this)->std::map<_Key, _Tp, _Compare, _Alloc>::_M_t._M_find_tr(__x)) std::map<_Key, _Tp, _Compare, _Alloc>::find(const _Kt&) const [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >]'
 1249 |         find(const _Kt& __x) const -> decltype(_M_t._M_find_tr(__x))
      |         ^~~~
/usr/include/c++/14/bits/stl_map.h:1249:9: note:   template argument deduction/substitution failed:
a.cc:44:28: note:   couldn't deduce template parameter '_Kt'
   44 |                 if (dp.find(next) == dp.end())
      |                     ~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_map.h:1218:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::find(const key_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >; iterator = std::_Rb_tree<std::__cxx11::basic_string<char>, std::pair<const std::__cxx11::basic_string<char>, int>, std::_Select1st<std::pair<const std::__cxx11::basic_string<char>, int> >, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> > >::iterator; key_type = std::__cxx11::basic_string<char>]'
 1218 |       find(const key_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_map.h:1218:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::map<std::__cxx11::basic_string<char>, int>::key_type&' {aka 'const std::__cxx11::basic_string<char>&'}
 1218 |       find(const key_type& __x)
      |            ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:1243:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::const_iterator std::map<_Key, _Tp, _Compare, _Alloc>::find(const key_type&) const [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >; const_iterator = std::_Rb_tree<std::__cxx11::basic_string<char>, std::pair<const std::__cxx11::basic_string<char>, int>, std::_Select1st<std::pair<const std::__cxx11::basic_string<char>, int> >, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> > >::const_iterator; key_type = std::__cxx11::basic_string<char>]'
 1243 |       find(const key_type& __x) const
      |       ^~~~
/usr/include/c++/14/bits/stl_map.h:1243:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::map<std::__cxx11::basic_string<char>, int>::key_type&' {aka 'const std::__cxx11::basic_string<char>&'}
 1243 |       find(const key_type& __x) const
      |            ~~~~~~~~~~~~~~~~^~~
a.cc:46:23: error: no match for 'operator[]' (operand types are 'std::map<std::__cxx11::basic_string<char>, int>' and '<unresolved overloaded function type>')
   46 |                     dp[next] = dp[now] + 1;
      |                       ^
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >; mapped_type = int; key_type = std::__cxx11::basic_string<char>]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::map<std::__cxx11::basic_string<char>, int>::key_type&' {aka 'const std::__cxx11::basic_string<char>&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::__cxx11::basic_string<char>; _Tp = int; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, int> >; mapped_type = int; key_type = std::__cxx11::basic_string<char>]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::map<std::__cxx11::basic_string<char>, int>::key_type&&' {aka 'std::__cxx11::basic_string<char>&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:47:29: error: no matching function for call to 'std::queue<std::__cxx11::basic_string<char> >::push(<unresolved overloaded function type>)'
   47 |                     que.push(next);
      |                     ~~~~~~~~^~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::__cxx11::basic_string<char>; _Sequence = std::deque<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >; value_type = std::__cxx11::basic_string<char>]'
  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<std::__cxx11::basic_string<char> >::value_type&' {aka 'const std::__cxx11::basic_string<char>&'}
  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 = std::__cxx11::basic_string<char>; _Sequence = std::deque<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char> > >; value_type = std::__cxx11::basic_string<char>]'
  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<std::__cxx11::basic_string<char> >::value_type&&' {aka 'std::__cxx11::basic_string<char>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc: At global scope:
a.cc:52:1: error: expected declaration before '}' token
   52 | }
      | ^