Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <cstdlib>

#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) (v).begin(), (v).end()
#define MP make_pair

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> P;
typedef vector<P> vp;

int dx[] = {0,  1, 0, -1}; // 下右上左
int dy[] = {-1, 0, 1, 0};


// それぞれの数字が上のとき、側面の数字反時計回り
int one[] = {4, 2, 3, 5, 4, 2, 3, 5};
int two[] = {4, 6, 3, 1, 4, 6, 3, 1};
int three[] = {1, 2, 6, 5, 1, 2, 6, 5};
int four[] = {1, 5, 6, 2, 1, 5, 6, 2};
int five[] = {1, 3, 6, 4, 1, 3, 6, 4};
int six[] = {2, 4, 5, 3, 2, 4, 5, 3};

// 6,5,4の方向を返す
vector<int> getdir(int top, int front){
	int *dirction;
	switch(top){
	case 1:
		dirction = one;break;
	case 2:
		dirction = two;break;
	case 3:
		dirction = three;break;
	case 4:
		dirction = four;break;
	case 5:
		dirction = five;break;
	case 6:
		dirction = six;break;
	}
	int start = 0;
	while(dirction[start] != front){
		start++;
	}
	int numdir[7];	// 4, 5, 6の方向を入れる
	memset(numdir, -1, sizeof(numdir));
	for(int i = 0; i < 4; i++){
		for(int j = 4; j <= 6; j++){
			if( dirction[start + i] ==  j ){
				numdir[j] = i;
				break;
			}
		}
	}
	vector<int> dirmap; // 6,5,4のdirを返す
	for(int i = 6; i >= 4; i--){
		if(numdir[i] != -1) dirmap.push_back(numdir[i]);
	}
	return dirmap;
}

// topとfrontを方向によって変える dirnumは0〜3
void changetf(int *top, int *front, int dirnum){
	int *dirction;
	switch(*top){
	case 1:
		dirction = one;break;
	case 2:
		dirction = two;break;
	case 3:
		dirction = three;break;
	case 4:
		dirction = four;break;
	case 5:
		dirction = five;break;
	case 6:
		dirction = six;break;
	}
	int start = 0;
	while(dirction[start] != *front){
		start++;
	}
	// この時点でdir[start]がfrontになってる 正面はstart+0, 右はstart+1 ...
	switch(dirnum){
		// 手前に転がるときnewtop = +2 , newfront = top
	case 0:
		*front = *top;
		break;
		// 右に転がるとき　newtop = +3 , newfront = front
	case 1:
		break;
		// 奥に転がるとき　newtop = +0 , newfront = 7-top
	case 2:
		*front = 7-*top;
		break;
		// 左に転がるとき　newtop = +1 , newfront = front
	case 3:
		break;
	}
	*top = dirction[(start+dirnum+2)%4];
}

int main(){

//	freopen( "c2.out", "w", stdout);

	int n;
	while(cin >> n, n){
		map<P, stack<int> > field;
		int numcount[6] = {0};
		while(n--){
			int top, front;
			int x = 0, y = 0;
			bool korokoro;

			cin >> top >> front;
			
			do{
				korokoro = false; // 転がる
				vector<int> dir;
				dir = getdir(top, front); // 6, 5, 4の方向が返ってくる
				rep(i, dir.size()){ // ころころ
					// 現在地と6, 5, 4の方向の高さを比べる
					if(field[MP(x, y)].size() > field[MP(x+dx[dir[i]], y+dy[dir[i]])].size()){
						// 現在地の方が高ければ、転がす
						x = x+dx[dir[i]];
						y = y+dy[dir[i]];
						changetf(&top, &front, dir[i]);
						korokoro = true;
						break;
					}
				}
			}while(korokoro);
			// 転がらなくなったら、現在地のスタックに上の面を突っ込む
			field[MP(x, y)].push(top);
		}
		// 全部処理したらmapの吐き出す
		map<P, stack<int> >::iterator it;
		for(it = field.begin(); it != field.end(); it++){
			if((*it).second.size() > 0){
				//cout << "***";
				//cout << (*it).second.top() << endl;
				numcount[(*it).second.top()-1]++;
			}
		}
		rep(i, 6){
			cout << (i?" ":"") << numcount[i];
		}
		cout << endl;
	}


	return 0;
}

Compiler output:
a.cc: In function 'std::vector<int> getdir(int, int)':
a.cc:57:9: error: 'memset' was not declared in this scope
   57 |         memset(numdir, -1, sizeof(numdir));
      |         ^~~~~~
a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    9 | #include <cstdlib>
  +++ |+#include <cstring>
   10 |