Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef struct dice{
	int x;
	int y;
	int z;
	int top;
	int front;
} dice;

dice D[100];
int tops[100][100][100];
//memset( tops, 0, sizeof(tops));
int z_top = -1;

void roll( int i){
	int x = D[i].x, y = D[i].y, z = D[i].z;
	if( D[i].z == 0 || tops[x+1][y][z-1] || tops[x-1][y][z-1] || tops[x][y+1][z-1] || tops[x][y-1][z-1] ) return;
	int bottom = 7 - D[i].top, back = 7 - D[i].front;
	if( D[i].front < back ){
		for( int j = 1; j <= 3; j++ ){
			if( j != bottom && j != D[i].top && j != D[i].front && j != back ){
				int left = j;
				int right = 7 - left;
			}
		}
	}
	if( max(D[i].front, max(back, max(left, right))) == right ){
		if( tops[x+1][y][z-1] == 0 ){
			D[i].x = x + 1;
			D[i].z = z - 1;
			D[i].top = left;
			tops[x+1][y][z-1] = 1;
			roll( i );
		}else if( back > 3 && tops[x][y+1][z-1] == 0 ){
			D[i].y = y + 1;
			D[i].z = z - 1;
			D[i].top = D[i].front;
			D[i].front = bottom;
			tops[x][y+1][z-1] = 1;
			roll( i );
		}else if( left > 3 && tops[x-1][y][z-1] == 0 ){
			D[i].x = x - 1;
			D[i].y = z - 1;
			D[i].top = right;
			tops[x-1][y][z-1] = 1;
			roll( i );
		}else if( D[i].front > 3 && tops[x][y-1][z-1] == 0 ){
			D[i].y = y - 1;
			D[i].y = z - 1;
			D[i].top = back;
			D[i].front = D[i].top;
			tops[x][y-1][z-1] = 1;
			roll( i );
		}
	}else if( max(D[i].front, max(back, max(left, right))) == left ){
		if( tops[x+1][y][z-1] == 0 ){
			D[i].x = x + 1;
			D[i].z = z - 1;
			D[i].top = left;
			tops[x+1][y][z-1] = 1;
			roll( i );
		}else if( back > 3 && tops[x][y+1][z-1] == 0 ){
			D[i].y = y + 1;
			D[i].z = z - 1;
			D[i].top = D[i].front;
			D[i].front = bottom;
			tops[x][y+1][z-1] = D[i].top;
			roll( i );
		}else if( right > 3 && tops[x-1][y][z-1] == 0 ){
			D[i].x = x - 1;
			D[i].y = z - 1;
			D[i].top = right;
			tops[x-1][y][z-1] = D[i].top;
			roll( i );
		}else if( D[i].front > 3 && tops[x][y-1][z-1] == 0 ){
			D[i].y = y - 1;
			D[i].y = z - 1;
			D[i].top = back;
			D[i].front = D[i].top;
			tops[x][y-1][z-1] = D[i].top;
			roll( i );
		}
	}if( max(D[i].front, max(back, max(left, right))) == D[i].front ){
		if( tops[x+1][y][z-1] == 0 ){
			D[i].x = x + 1;
			D[i].z = z - 1;
			D[i].top = left;
			tops[x+1][y][z-1] = D[i].top;
			roll( i );
		}else if( back > 3 && tops[x][y+1][z-1] == 0 ){
			D[i].y = y + 1;
			D[i].z = z - 1;
			D[i].top = D[i].front;
			D[i].front = bottom;
			tops[x][y+1][z-1] = D[i].top;
			roll( i );
		}else if( left > 3 && tops[x-1][y][z-1] == 0 ){
			D[i].x = x - 1;
			D[i].y = z - 1;
			D[i].top = right;
			tops[x-1][y][z-1] = D[i].top;
			roll( i );
		}else if( right > 3 && tops[x][y-1][z-1] == 0 ){
			D[i].y = y - 1;
			D[i].y = z - 1;
			D[i].top = back;
			D[i].front = D[i].top;
			tops[x][y-1][z-1] = D[i].top;
			roll( i );
		}
	}if( max(D[i].front, max(back, max(left, right))) == back ){
		if( tops[x+1][y][z-1] == 0 ){
			D[i].x = x + 1;
			D[i].z = z - 1;
			D[i].top = left;
			tops[x+1][y][z-1] = D[i].top;
			roll( i );
		}else if( right > 3 && tops[x][y+1][z-1] == 0 ){
			D[i].y = y + 1;
			D[i].z = z - 1;
			D[i].top = D[i].front;
			D[i].front = bottom;
			tops[x][y+1][z-1] = D[i].top;
			roll( i );
		}else if( left > 3 && tops[x-1][y][z-1] == 0 ){
			D[i].x = x - 1;
			D[i].y = z - 1;
			D[i].top = right;
			tops[x-1][y][z-1] = D[i].top;
			roll( i );
		}else if( D[i].front > 3 && tops[x][y-1][z-1] == 0 ){
			D[i].y = y - 1;
			D[i].y = z - 1;
			D[i].top = back;
			D[i].front = D[i].top;
			tops[x][y-1][z-1] = D[i].top;
			roll( i );
		}
	}
	if( D[i].z > z_top ) z_top = D[i].z;
}

int output[6];

int main(){
	int n;
	while( 1 ){
		cin >> n;
		if( n == 0 ) break;
		D[0].x = 50; D[0].y = 50; D[0].z = 0;
		for( int i = 0; i < n; i++ ){
			cin >> D[i].top >> D[i].front;
			D[i].z = z_top + 1;
			roll( i );
		}
		for( int i = 0; i < n; i++ ){
			for( int j = 1; j <= 6; j++ ){
				if( D[i].top == j ){
					output[j-1]++;
				}
			}
		}
		for( int i = 0; i < 6; i++ ){
			cout << output[i] << ' ';
		}
		cout << endl;
	}
}

Compiler output:
a.cc: In function 'void roll(int)':
a.cc:31:32: error: no matching function for call to 'max(int&, std::ios_base& (&)(std::ios_base&))'
   31 |         if( max(D[i].front, max(back, max(left, right))) == right ){
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:31:32: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::ios_base&(std::ios_base&)')
   31 |         if( max(D[i].front, max(back, max(left, right))) == right ){
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:31:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   31 |         if( max(D[i].front, max(back, max(left, right))) == right ){
      |                             ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:35:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   35 |                         D[i].top = left;
      |                                    ^~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:45:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   45 |                 }else if( left > 3 && tops[x-1][y][z-1] == 0 ){
      |                           ~~~~~^~~
a.cc:48:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   48 |                         D[i].top = right;
      |                                    ^~~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:59:38: error: no matching function for call to 'max(int&, std::ios_base& (&)(std::ios_base&))'
   59 |         }else if( max(D[i].front, max(back, max(left, right))) == left ){
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:59:38: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::ios_base&(std::ios_base&)')
   59 |         }else if( max(D[i].front, max(back, max(left, right))) == left ){
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:59:38: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   59 |         }else if( max(D[i].front, max(back, max(left, right))) == left ){
      |                                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:63:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   63 |                         D[i].top = left;
      |                                    ^~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:73:33: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   73 |                 }else if( right > 3 && tops[x-1][y][z-1] == 0 ){
      |                           ~~~~~~^~~
a.cc:76:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   76 |                         D[i].top = right;
      |                                    ^~~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:87:33: error: no matching function for call to 'max(int&, std::ios_base& (&)(std::ios_base&))'
   87 |         }if( max(D[i].front, max(back, max(left, right))) == D[i].front ){
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:87:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::ios_base&(std::ios_base&)')
   87 |         }if( max(D[i].front, max(back, max(left, right))) == D[i].front ){
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:87:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   87 |         }if( max(D[i].front, max(back, max(left, right))) == D[i].front ){
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:91:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
   91 |                         D[i].top = left;
      |                                    ^~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:101:32: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  101 |                 }else if( left > 3 && tops[x-1][y][z-1] == 0 ){
      |                           ~~~~~^~~
a.cc:104:36: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'int' [-fpermissive]
  104 |                         D[i].top = right;
      |                                    ^~~~~
      |                                    |
      |                                    std::ios_base& (*)(std::ios_base&)
a.cc:107:33: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  107 |                 }else if( right > 3 && tops[x][y-1][z-1] == 0 ){
      |                           ~~~~~~^~~
a.cc:115:33: error: no matching function for call to 'max(int&, std::ios_base& (&)(std::ios_base&))'
  115 |         }if( max(D[i].front, max(back, max(left, right))) == back ){
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:115:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::ios_base&(std::ios_base&)')
  115 |         }if( max(D[i].front, max(back, max(left, right))) == back ){
      |                              ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'