Language: C++

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

string pat[24] =
{
	"123","135","154","142",
	"231","214","246","263",
	"326","365","351","312",
	"421","415","456","462",
	"513","536","564","541",
	"624","645","653","632"
};

string dice[8];
bool used[8];
int select[8];
int num[8];

bool check(int d1, int pos1, int d2, int pos2) {
	char c1 = dice[select[d1]][pat[num[d1]][pos1 - 1] - '1'];
	char c2 = dice[select[d2]][pat[num[d2]][pos2 - 1] - '1'];
	return c1 != c2 && (c1 - 32 == c2 || c2 - 32 == c1);
}

bool dfs(int p) {
	if (p == 8) return true;
	
	REP(i, 8) if (!used[i]) {
		used[i] = true;
		select[p] = i;
		REP(j, 24) {
			num[p] = j;
			bool flag = false;
			switch (p) {
				case 0: flag = true; break;
				case 1: if (check(0, 3, 1, 4)) flag = true; break;
				case 2: if (check(0, 2, 2, 5)) flag = true; break;
				case 3: if (check(1, 2, 3, 5) && check(2, 3, 3, 4)) flag = true; break;
				case 4: if (check(0, 6, 4, 1)) flag = true; break;
				case 5: if (check(1, 6, 5, 1) && check(4, 3, 5, 4)) flag = true; break;
				case 6: if (check(4, 2, 6, 5) && check(2, 6, 6, 1)) flag = true; break;
				case 7: if (check(6, 3, 7, 4) && check(5, 2, 7, 5) && check(3, 6, 7, 1)) flag = true; break;
			}
			if (flag && dfs(p + 1)) return true;
		}
		used[i] = false;
	}
	return false;
}

int main() {
	REP(i, 24) {
		for (int j = 2; j >= 0; j--) pat[i] += (7 - (pat[i][j] - '0')) + '0';
	}
	
	while (cin >> dice[0]) {
		if (dice[0] == "0") break;
		
		FOR(i, 1, 8) cin >> dice[i];
		
		memset(used, 0, sizeof(used));
		
		if (dfs(0))	puts("YES");
		else puts("NO");
	}
	return 0;
}

Compiler output:
a.cc:19:13: error: 'int select [8]' redeclared as different kind of entity
   19 | int select[8];
      |             ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:514,
                 from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/sys/select.h:102:12: note: previous declaration 'int select(int, fd_set*, fd_set*, fd_set*, timeval*)'
  102 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
a.cc: In function 'bool check(int, int, int, int)':
a.cc:23:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         char c1 = dice[select[d1]][pat[num[d1]][pos1 - 1] - '1'];
      |                                 ^
a.cc:23:23: error: invalid types 'std::string [8] {aka std::__cxx11::basic_string<char> [8]}[int(int, fd_set*, fd_set*, fd_set*, timeval*)]' for array subscript
   23 |         char c1 = dice[select[d1]][pat[num[d1]][pos1 - 1] - '1'];
      |                       ^
a.cc:24:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |         char c2 = dice[select[d2]][pat[num[d2]][pos2 - 1] - '1'];
      |                                 ^
a.cc:24:23: error: invalid types 'std::string [8] {aka std::__cxx11::basic_string<char> [8]}[int(int, fd_set*, fd_set*, fd_set*, timeval*)]' for array subscript
   24 |         char c2 = dice[select[d2]][pat[num[d2]][pos2 - 1] - '1'];
      |                       ^
a.cc: In function 'bool dfs(int)':
a.cc:33:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |                 select[p] = i;
      |                         ^
a.cc:33:27: error: assignment of read-only location '*(select + ((sizetype)p))'
   33 |                 select[p] = i;
      |                 ~~~~~~~~~~^~~