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<algorithm>
#include<iostream>
#include<string>
#include<set>
using namespace std;
string face[6];
int n;
int main(){
  while(cin >> n, n){
    set<string> ans;
    for(int j = 0;j < n;j++){
      cin >> face[0] >> face[1] >> face[2] >> face[3] >> face[4] >> face[5];
      string p;
      for(int i = 0;i < 4;i++){
	if(face[0] == "Blue")break;
	swap(face[0], face[1]);
	swap(face[1], face[5]);
	swap(face[5], face[3]);
      }
      for(int i = 0;i < 4;i++){
	if(face[0] == "Blue")break;
	swap(face[0], face[2]);
	swap(face[2], face[5]);
	swap(face[5], face[4]);
      }
      for(int i = 1;i < 5;i++){
	if(i == 1)p = face[i];
	p = min(p, face[i]);
      }
      while(face[1] != p){
	swap(face[1], face[4]);
	swap(face[3], face[4]);
	swap(face[2], face[3]);
      }
      string res ="";
      for(int i = 0;i < 6;i++){
	res += face[i][0];
      }
      cout << res << endl;
      ans.insert(res);
    }
    cout << n - ans.size() << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
	int a, b[101][101] = { 0 }, ruio = 0;
	char str[101];
	while (1) {
		cin >> a;
		if (a == 0)return 0;
		ruio = a;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				scanf("%s", str);
				if (strstr(str, "Red") != NULL) {
					b[i][j] = 1;
				}
				if (strstr(str, "Yellow") != NULL) {
					b[i][j] = 2;
				}
				if (strstr(str, "Blue") != NULL) {
					b[i][j] = 3;
				}
				if (strstr(str, "Magenta") != NULL) {
					b[i][j] = 4;
				}
				if (strstr(str, "Green") != NULL) {
					b[i][j] = 5;
				}
				if (strstr(str, "Cyan") != NULL) {
					b[i][j] = 6;
				}
			}
		}
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= 6; j++) {
				cout << b[i][j] << ",";
			}
			cout << endl;
		}

		int tatuo = 0;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= a; j++) {
				if (j != i && b[j][1] != -1 && b[i][1] != -1) {
					if (b[i][1] + b[i][6] == b[j][1] + b[j][6]) {
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
						//	if (tatuo > 0)break;
						}
						else if (b[i][3] + b[i][4] == b[j][2] + b[j][5]) {
							if (b[i][2] + b[i][5] == b[j][3] + b[j][4]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
						}
						//if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][3] + b[j][4]) {
						if (b[i][3] + b[i][4] == b[j][2] + b[j][5]) {
							if (b[i][2] + b[i][5] == b[j][1] + b[j][6]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							//if (tatuo > 0)break;
						}
						else if (b[i][3] + b[i][4] == b[j][1] + b[j][6]) {
							if (b[i][2] + b[i][5] == b[j][2] + b[j][5]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
						}
						//if (tatuo > 0)break;
					}
					else if (b[i][1] + b[i][6] == b[j][2] + b[j][5]) {
						if (b[i][3] + b[i][4] == b[j][1] + b[j][6]) {
							if (b[i][2] + b[i][5] == b[j][3] + b[j][4]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							//if (tatuo > 0)break;
						}
						if (b[i][3] + b[i][4] == b[j][3] + b[j][4]) {
							if (b[i][2] + b[i][5] == b[j][1] + b[j][6]) {
								b[i][1] = -1;
								ruio--;
								tatuo++;
							}
							//if (tatuo > 0)break;
						}
						//if (tatuo > 0)break;
					}
					//if (tatuo > 0) break;
				}
				//if (tatuo > 0) {
					//tatuo = 0;
					//break;
				//}
			}
		}
		cout << a - ruio << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
  
enum { TOP=0, FRONT=1, LEFT=2, RIGHT=3, BACK=4, BOTTOM=5 };
enum { WEST = 0, NORTH=1, EAST=2, SOUTH=3 };
  
class Dice
{
private:
  int num[6];
   
public:
    
  int getTop()    { return num[TOP];    }
  int getBottom() { return num[BOTTOM]; }
  int getFront()  { return num[FRONT];  }
  int getBack()   { return num[BACK];   }
  int getLeft()   { return num[LEFT];   }
  int getRight()  { return num[RIGHT];  }
    
  void roll(int dir)
  {
    int tmp;
    switch(dir) {
    case EAST:
      tmp = num[RIGHT];
      num[RIGHT] = num[TOP];
      num[TOP] = num[LEFT];
      num[LEFT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
        
    case WEST:
      tmp = num[LEFT];
      num[LEFT] = num[TOP];
      num[TOP] = num[RIGHT];
      num[RIGHT] = num[BOTTOM];
      num[BOTTOM] = tmp;
      break;
        
    case NORTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[FRONT];
      num[FRONT] = num[TOP];
      num[TOP] = num[BACK];
      num[BACK] = tmp;
      break;
        
    case SOUTH:
      tmp = num[BOTTOM];
      num[BOTTOM] = num[BACK];
      num[BACK] = num[TOP];
      num[TOP] = num[FRONT];
      num[FRONT] = tmp;
      break;
        
    }
  }
   
  void rightHandedRoll() {
    int tmp = num[FRONT];
    num[FRONT] = num[RIGHT];
    num[RIGHT] = num[BACK];
    num[BACK] = num[LEFT];
    num[LEFT] = tmp;
  }
    
  Dice() {
  }
   
  Dice(int t, int f, int l, int r, int b, int m)
  {
    num[TOP] = t, num[FRONT] = f, num[LEFT] = l, num[RIGHT] = r, num[BACK] = b, num[BOTTOM] = m;
  }
  Dice(vector<int> v)
  {
    Dice(v[0], v[1], v[2], v[3], v[4], v[5]);
  }
   
  bool equals (Dice rhs) const {
    for(int i=0; i<4; i++) {
      rhs.roll(NORTH);
      if(num[TOP] == rhs.getTop()) break;
      rhs.roll(WEST);
      if(num[TOP] == rhs.getTop()) break;
    }
    for(int i=0; i<4; i++) {
      if(check(rhs)) return true;
      else rhs.rightHandedRoll();
    }
    return false;
  }
   
private:
  bool check(const Dice& rhs) const {
    for(int i=0; i<6; i++) {
      if(num[i]!=rhs.num[i]) return false;
    }
    return true;
  }
   
};
 
map<string, int> mp;
 
int main() {
   
  mp["Red"]=0, mp["Yellow"]=1, mp["Blue"]=2, mp["Magenta"]=3, mp["Green"]=4, mp["Cyan"]=5;
  int N;
  while(cin >> N && N) {
    vector<Dice> d;
    for(int i=0; i<N; i++) {
      vector<int> v(6);
      for(int j=0; j<6; j++) {
        string s; cin >> s; v[j] = mp[s];
      }
      swap(v[2], v[3]);
      d.push_back(Dice(v));
    }
     
    int cnt = 0;
    bool update = true;
    while(update) {
      update = false;
      for(int i=0; i<d.size(); i++) {
        for(int j=i+1; j<d.size(); j++) {
          if(d[i].equals(d[j])) {
            d.erase(d.begin()+j);
            update = true; cnt ++;
            goto NEXT;
          }
        }
      }
    NEXT:;
    }
    cout << cnt << endl;
  }
   
  return 0;
}