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<iostream>
#include<vector>
using namespace std;

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

int main(){
    int n;
    while(cin >> n, n){
        string die[n][6];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 6; j++){
                cin >> die[i][j];
            }
        }
        vector<bool> ng(n, 0);
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                int k;
                for(k = 0; k < 6; k++)  if(die[i][0] == die[j][k])  break;
                for(int kaiten = 0; kaiten < 4; kaiten++){
                    bool cw = true;
                    for(int l = 0; l < 4; l++){
                        cw &= die[i][rot[0][l]] == die[j][rot[k][(kaiten+l)%4]];
                    }
                    if(cw){
                        ng[j] = true;
                    }
                }
            }
        }
        int ans = 0;
        for(int i = 0; i < n; i++)  ans += ng[i];
        cout << ans << endl;
    }
    return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j,k,l;
  int a[30][6],b[6],n;
  string s[]={"Cyan","Yellow","Red","Magenta","Green","Blue"},t;
  while(cin>>n&&n){
    l=0;
    for(i=0;i<n-l;i++){
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][0]=j;
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][1]=j;
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][2]=j;
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][4]=j;
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][3]=j;
      cin>>t;
      for(j=0;s[j]!=t;j++);
      a[i][5]=j;
      for(j=0;j<i;j++){
	memcpy(b,&a[i][0],6*sizeof(int));
	for(k=0;b[k]!=a[j][0];k++);
	if(0){
	}else if(k==0){
	}else if(k==1){
	  swap(b[3],b[0]);
	  swap(b[0],b[1]);
	  swap(b[1],b[5]);	  
	}else if(k==2){
	  swap(b[4],b[0]);
	  swap(b[0],b[2]);
	  swap(b[2],b[5]);
	}else if(k==3){
	  swap(b[1],b[0]);
	  swap(b[0],b[3]);
	  swap(b[3],b[5]);
	}else if(k==4){
	  swap(b[2],b[0]);
	  swap(b[0],b[4]);
	  swap(b[4],b[5]);
	}else if(k==5){
	  swap(b[3],b[0]);
	  swap(b[0],b[1]);
	  swap(b[1],b[5]);
	  swap(b[3],b[0]);
	  swap(b[0],b[1]);
	  swap(b[1],b[5]);
	}
	for(k=0;k<4;k++){
	  if(b[0]==a[j][0]&&b[1]==a[j][1]&&b[2]==a[j][2]&&b[3]==a[j][3]&&b[4]==a[j][4]&&b[5]==a[j][5])
	    break;
	  swap(b[4],b[1]);
	  swap(b[1],b[2]);
	  swap(b[2],b[3]);
	}
	if(k!=4){
	  i--;
	  l++;
	  break;
	}
      }
    }
    cout<<l<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	string str;
	int d[6];
	int n,i,j,r;
	for(;cin>>n,n;){
		set<long long>s;
		for(r=i=0;i<n;i++){
			for(j=0;j<6;j++)cin>>str,d[j]=str[0];
			long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
			if(s.find(x)!=s.end())r++;
			else{
				dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
				di.all_rolls(s);
			}
		}
		cout<<r<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#include<algorithm>

int colorToInt(std::string s){
	const	char cs[] = {'C', 'Y', 'R', 'M', 'G', 'B'};
	for(int i=0;i<6;i++){
		if(s[0] == cs[i]){
			return i;
		}
	}
}

int main(){
	int n;
	while(std::cin >> n, n){
		std::vector<int> cube_v;

		for(int i=0;i<n;i++){
			int cs[6];
			for(int j=0;j<6;j++){
				std::string c;
				std::cin >> c;
				cs[j] = colorToInt(c);
			}

			//Cyanをc1, c2, c3のどれかに入れる
			if(cs[3] == 0 || cs[4] == 0 || cs[5] == 0){
				std::swap(cs[0], cs[5]);
				std::swap(cs[1], cs[4]);
				std::swap(cs[2], cs[3]);
			}

			//Cyanをc1に来させる
			if(cs[1] == 0){
				std::swap(cs[1], cs[0]);
				std::swap(cs[4], cs[5]);
			}
			if(cs[2] == 0){
				std::swap(cs[2], cs[0]);
				std::swap(cs[3], cs[5]);
			}

			if(cs[4] < cs[1]){
				std::swap(cs[1], cs[4]);
			}
			if(cs[3] < cs[2]){
				std::swap(cs[2], cs[3]);
			}
			if(cs[2] < cs[1]){
				std::swap(cs[1], cs[2]);
				std::swap(cs[3], cs[4]);
			}

			int cube = 0;
			for(int i=0;i<6;i++){
				cube = (cube << 3) + cs[i];
			}

			if(std::find(cube_v.begin(), cube_v.end(), cube) == cube_v.end()){
				cube_v.push_back(cube);
			}
		}

		std::cout << (n-cube_v.size()) << std::endl;
	}
}