Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
		"reflect"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	// 上面の色を固定してから、左右方向に回転して一致するものがあるかを調べる
	round := [][]int{
		{1,2,3,4,5,6}, {1,3,5,2,4,6}, {1,4,2,5,3,6}, {1,5,4,3,2,6}, // c1を上面に固定して回転
		{2,6,3,4,1,5}, {2,3,1,6,4,5}, {2,1,4,3,6,5}, {2,4,6,1,3,5}, // c2を上面に固定して回転
		{3,1,2,5,6,4}, {3,2,6,1,5,4}, {3,5,1,6,2,4}, {3,6,5,2,1,4}, // c3を上面に固定して回転
		{4,1,5,2,6,3}, {4,2,1,6,5,3}, {4,5,6,1,2,3}, {4,6,2,5,1,3}, // c4を上面に固定して回転
		{5,1,3,4,6,2}, {5,3,6,1,4,2}, {5,4,1,6,3,2}, {5,6,4,3,1,2}, // c5を上面に固定して回転
		{6,2,4,3,5,1}, {6,3,2,5,4,1}, {6,5,3,4,2,1}, {6,4,5,2,3,1}, // c6を上面に固定して回転

	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		cubes := make([][]string, n)
		for i := 0; i < n; i++ {
			scanner.Scan()
			cubes[i] = strings.Split(scanner.Text(), " ")
		}
		check := func(a, b int) bool {
			tmp := make([]string, 6)
			for i := 0; i < 24; i++ {
				for j := 0; j < 6; j++ {
					tmp[j] = cubes[b][round[i][j]-1]
				}
				if reflect.DeepEqual(tmp, cubes[a]) {
					return true
				}
			}
			return false
		}
		tbl := make([]int, n)
		// 全ての組み合わせを調べる
		for i := 0; i < n; i++ {
			if tbl[i] == 1 {
				continue
			}
			for j := i+1; j < n; j++ {
				if check(i, j) {
					tbl[j] = 1
				}
			}
		}
		fmt.Println(sum(tbl))
	}
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

C++: #include <cstdio>
#include <string>

using namespace std;

int rot[6][4] = {{2, 4, 3, 1}, {2, 0, 3, 5}, {5, 4, 0, 1}, {0, 4, 5, 1}, {2, 5, 3, 0}, {3, 4, 2, 1}};

string board[30][6];

bool same(int a, int b)
{
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 6; j++){
			if (board[a][i] != board[b][j]) continue;
			for (int dx = 0; dx < 4; dx++){
				bool same = true;
				for (int k = 0; k < 4; k++){
					if (board[a][rot[i][(k + dx) % 4]] != board[b][rot[j][k]])
						same = false;
				}
				if (same) return (true);
			}
		}
	}
	return (false);
}

int main()
{
	int n;
	while (scanf("%d", &n) && n){
		int ct = 0;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 6; j++){
				char tmp[64];
				scanf("%s", tmp);
				board[i][j] = tmp;
			}
			bool ok = true;
			for (int j = 0; j < i; j++) if (same(i, j)) ok = false;
			ct += ok;
		}
		
		printf("%d\n", n - ct);
	}	
}

C++: #include<iostream>

#define inf 1000000000

using namespace std;

int main(){
	while(1){
		int n;
		cin>>n;
		if(!n)break;
		int check[6][6][6][6][6][6]={0};
		for(int i=0;i<n;i++){
			int s[7];
			for(int j=1;j<=6;j++){
				string a;
				cin>>a;
				switch(a[0]){
					case 'C':s[j]=0;break;
					case 'Y':s[j]=1;break;
					case 'R':s[j]=2;break;
					case 'M':s[j]=3;break;
					case 'G':s[j]=4;break;
					case 'B':s[j]=5;break;
				}
			}
			int bin;
			for(int i=0;i<4;i++){
				bin=s[1];
				s[1]=s[5];
				s[5]=s[6];
				s[6]=s[2];
				s[2]=bin;
				for(int j=0;j<4;j++){
					bin=s[2];
					s[2]=s[3];
					s[3]=s[5];
					s[5]=s[4];
					s[4]=bin;
					check[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]]=1;
				}
			}
			
			
					bin=s[1];
					s[1]=s[3];
					s[3]=s[6];
					s[6]=s[4];
					s[4]=bin;
				for(int j=0;j<4;j++){
					bin=s[2];
					s[2]=s[3];
					s[3]=s[5];
					s[5]=s[4];
					s[4]=bin;
					check[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]]=1;
				}
					bin=s[1];
					s[1]=s[3];
					s[3]=s[6];
					s[6]=s[4];
					s[4]=bin;
					bin=s[1];
					s[1]=s[3];
					s[3]=s[6];
					s[6]=s[4];
					s[4]=bin;
				for(int j=0;j<4;j++){
					bin=s[2];
					s[2]=s[3];
					s[3]=s[5];
					s[5]=s[4];
					s[4]=bin;
					check[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]]=1;
				}
		}
		
		int cont=0;
		for(int a=0;a<6;a++)
		for(int b=0;b<6;b++)
		for(int c=0;c<6;c++)
		for(int d=0;d<6;d++)
		for(int e=0;e<6;e++)
		for(int f=0;f<6;f++)
		cont+=check[a][b][c][d][e][f];
		
		printf("%d\n",n-cont/24);
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
long n,i,j,k;
string c,s[30],s2;
while(cin>>n){
if(n==0)break;
for(j=0;j<n;j++){
s[j]="      ";
for(i=0;i<6;i++){
cin>>c;
if(c=="Red")s[j][i]='r';
else if(c=="Yellow")s[j][i]='y';
else if(c=="Blue")s[j][i]='b';
else if(c=="Magenta")s[j][i]='m';
else if(c=="Green")s[j][i]='g';
else if(c=="Cyan")s[j][i]='c';
}
i=s[j].find('r');
     if(i==1){s2="";s2+=s[j][1];s2+=s[j][2];s2+=s[j][0];s2+=s[j][5];s2+=s[j][3];s2+=s[j][4];s[j]=s2;}
else if(i==2){s2="";s2+=s[j][2];s2+=s[j][0];s2+=s[j][1];s2+=s[j][4];s2+=s[j][5];s2+=s[j][3];s[j]=s2;}
else if(i==3){s2="";s2+=s[j][3];s2+=s[j][1];s2+=s[j][0];s2+=s[j][5];s2+=s[j][4];s2+=s[j][1];s[j]=s2;}
else if(i==4){s2="";s2+=s[j][4];s2+=s[j][0];s2+=s[j][2];s2+=s[j][3];s2+=s[j][5];s2+=s[j][1];s[j]=s2;}
else if(i==5){s2="";s2+=s[j][5];s2+=s[j][2];s2+=s[j][1];s2+=s[j][4];s2+=s[j][3];s2+=s[j][0];s[j]=s2;}
i=s[j].find('y');
     if(i==2){s2="";s2+=s[j][0];s2+=s[j][2];s2+=s[j][4];s2+=s[j][1];s2+=s[j][3];s2+=s[j][5];s[j]=s2;}
else if(i==3){s2="";s2+=s[j][0];s2+=s[j][3];s2+=s[j][1];s2+=s[j][4];s2+=s[j][2];s2+=s[j][5];s[j]=s2;}
else if(i==4){s2="";s2+=s[j][0];s2+=s[j][4];s2+=s[j][3];s2+=s[j][2];s2+=s[j][1];s2+=s[j][5];s[j]=s2;}
else if(i==5){
i=s[j].find('m');
     if(i==2){s2="";s2+=s[j][0];s2+=s[j][2];s2+=s[j][4];s2+=s[j][1];s2+=s[j][3];s2+=s[j][5];s[j]=s2;}
else if(i==3){s2="";s2+=s[j][0];s2+=s[j][3];s2+=s[j][1];s2+=s[j][4];s2+=s[j][2];s2+=s[j][5];s[j]=s2;}
else if(i==4){s2="";s2+=s[j][0];s2+=s[j][4];s2+=s[j][3];s2+=s[j][2];s2+=s[j][1];s2+=s[j][5];s[j]=s2;}
}
}
for(k=0,i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(s[i]==s[j])k++;
}
}
cout<<k<<endl;
}
return 0;
}