Language: C++

#include <iostream>
#include <string>

using namespace std;


char data[24][6] = {{0, 1, 2, 3, 4, 5}, {0, 3, 1, 4, 2, 5}, {0, 4, 3, 2, 1, 5}, {0, 2, 4, 1, 3, 5},
		    {1, 5, 2, 3, 0, 4}, {1, 3, 5, 0, 2, 4}, {1, 0, 3, 2, 5, 4}, {1, 2, 0, 5, 3, 4},
		    {2, 5, 4, 1, 0, 3}, {2, 1, 5, 0, 4, 3}, {2, 0, 1, 4, 5, 3}, {2, 4, 0, 5, 1, 3},
		    {3, 5, 1, 4, 0, 2}, {3, 4, 5, 0, 1, 2}, {3, 0, 4, 1, 5, 2}, {3, 1, 0, 5, 4, 2},
		    {4, 5, 3, 2, 0, 1}, {4, 2, 5, 0, 3, 1}, {4, 0, 2, 3, 5, 1}, {4, 3, 0, 5, 2, 1},
		    {5, 4, 2, 3, 1, 0}, {5, 3, 4, 1, 2, 0}, {5, 1, 3, 2, 4, 0}, {5, 3, 1, 4, 2, 0}};
string dice[8];
bool used[8];
int id[8][3] = {{},
		{0},
		{0},
		{1, 2},
		{0},
		{1, 4},
		{2, 4},
		{3, 5, 6}};
int face[8][3] = {{},
		  {2},
		  {5},
		  {5, 2},
		  {4},
		  {4, 2},
		  {4, 0},
		  {4, 5, 2}};
int size[8] = {0, 1, 1, 2, 1, 2, 2, 3};
pair<int, int> now[8];

bool solve(int pos){
  if(pos == 8) return true;
  for(int i=0;i<8;i++){
    if(used[i]) continue;
    used[i] = true;
    for(int j=0;j<24;j++){
      bool f = true;
      for(int k=0;k<size[pos];k++){
	int idx = id[pos][k];
	int a = dice[now[idx].first][data[now[idx].second][face[pos][k]]];
	int b = dice[i][data[j][5-face[pos][k]]];
	if(abs(a-b) != (int)('a' - 'A')) f = false;
      }
      if(!f) continue;
      now[pos] = make_pair(i, j);
      if(solve(pos+1)) return true;
    }
    used[i] = false;
  }
  return false;
}

main(){
  while(cin >> dice[0]){
    if(dice[0] == "0") break;
    for(int i=1;i<8;i++){
      cin >> dice[i];
    }
    fill(used, used+8, false);
    cout << (solve(0)?"YES":"NO") << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'bool solve(int)':
a.cc:41:21: error: reference to 'size' is ambiguous
   41 |       for(int k=0;k<size[pos];k++){
      |                     ^~~~
In file included from /usr/include/c++/14/string:53,
                 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,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:31:5: note:                 'int size [8]'
   31 | int size[8] = {0, 1, 1, 2, 1, 2, 2, 3};
      |     ^~~~
a.cc:43:38: error: reference to 'data' is ambiguous
   43 |         int a = dice[now[idx].first][data[now[idx].second][face[pos][k]]];
      |                                      ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [24][6]'
    7 | char data[24][6] = {{0, 1, 2, 3, 4, 5}, {0, 3, 1, 4, 2, 5}, {0, 4, 3, 2, 1, 5}, {0, 2, 4, 1, 3, 5},
      |      ^~~~
a.cc:44:25: error: reference to 'data' is ambiguous
   44 |         int b = dice[i][data[j][5-face[pos][k]]];
      |                         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:6: note:                 'char data [24][6]'
    7 | char data[24][6] = {{0, 1, 2, 3, 4, 5}, {0, 3, 1, 4, 2, 5}, {0, 4, 3, 2, 1, 5}, {0, 2, 4, 1, 3, 5},
      |      ^~~~
a.cc: At global scope:
a.cc:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main(){
      | ^~~~