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>
#include <iostream>

using namespace std;

int n;
string str[31][6];

bool roll(int x,int y){
	bool flag2=false;
	for(int i=0;i<4;i++){
		string st=str[y][1];
		str[y][1]=str[y][2];
		str[y][2]=str[y][4];
		str[y][4]=str[y][3];
		str[y][3]=st;
		bool flag=true;
		for(int j=0;j<6;j++){
			if(str[y][j]!=str[x][j])flag=false;
		}
		if(flag)flag2=true;
	}
	return flag2;
}

bool check(int x,int y){
	bool flag=true;
	if(roll(x,y))flag=false;
	for(int i=0;i<4;i++){
		string st=str[y][0];
		str[y][0]=str[y][2];
		str[y][2]=str[y][5];
		str[y][5]=str[y][3];
		str[y][3]=st;
		if(roll(x,y))flag=false;
	}
	for(int i=0;i<4;i++){
		string st=str[y][0];
		str[y][0]=str[y][1];
		str[y][1]=str[y][5];
		str[y][5]=str[y][4];
		str[y][4]=st;
		if(roll(x,y))flag=false;
	}
	return flag;
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			for(int j=0;j<6;j++){
				cin >> str[i][j];
			}
		}
		int cnt=0;
		for(int i=0;i<n;i++){
			bool flag=true;
			for(int j=0;j<i;j++){
				if(!check(i,j))flag=false;
			}
			if(flag)cnt++;
		}
		printf("%d\n",n-cnt);
	}
	return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
char cube[30][6];

int main()
{
	int n;
	while(cin >> n){
		if(n==0)
			break;
		string str;
		for(int i=0;i<n;i++){
			for(int j=0;j<6;j++){
				cin >> str;
				cube[i][j] = str[0];
			}
		}
		int count = 0;
		for(int i=0;i<n-1;i++){
			bool flag=false,flug=false;
			string so = "";
			so += cube[i][3];
			so += cube[i][0];
			so += cube[i][2];
			so += cube[i][5];
			for(int j=i+1;j<n;j++){
				//2,5»è
				if((cube[i][1] == cube[j][1] && cube[i][4] == cube[j][4]) || (cube[i][1] == cube[j][4] && cube[i][4] == cube[j][1]))
					flag = true;
				//cè»è
				string ds = "";
				ds += cube[j][3];
				ds += cube[j][0];
				ds += cube[j][2];
				ds += cube[j][5];
				string dds = "";
				dds += cube[j][5];
				dds += cube[j][2];
				dds += cube[j][0];
				dds += cube[j][3];
				if(so == ds || so == dds)
					flug = true;
				if(flag && flug){
					count++;
					break;
				}
				//ÇÁ¿à¨kÅJEg{{uCN
			}
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
??
int main()
{
????????int i0, i1, i2, i3, n, m, d[30][6], s[30], sw;
????????char c[8];
????????char color[6][8] = {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};
??
????????scanf("%d", &n);
????????while (n > 0) {
????????????????for (i0 = 0; i0 < n; i0++) {
????????????????????????for (i1 = 0; i1 < 6; i1++) {
????????????????????????????????scanf("%s", c);
????????????????????????????????for (i2 = 0; i2 < 6; i2++) {
????????????????????????????????????????if (strcmp(c, color[i2]) == 0) {
????????????????????????????????????????????????d[i0][i1] = i2;
????????????????????????????????????????????????break;
????????????????????????????????????????}
????????????????????????????????}
????????????????????????}
????????????????}
????????????????m = 0;
????????????????for (i0 = 0; i0 < n; i0++)
????????????????????????s[i0] = 1;
????????????????for (i0 = 0; i0 < n; i0++) {
????????????????????????if (s[i0] > 0) {
????????????????????????????????m++;
????????????????????????????????s[i0] = 0;
????????????????????????????????for (i1 = i0+1; i1 < n; i1++) {
????????????????????????????????????????sw = 0;
????????????????????????????????????????for (i2 = 0; i2 < 6 && sw == 0; i2++) {
????????????????????????????????????????????????for (i3 = 0; i3 < 6 && sw == 0; i3++) {
????????????????????????????????????????????????????????if (d[i0][i2] == d[i1][i3]) {
????????????????????????????????????????????????????????????????if (d[i0][5-i2] != d[i1][5-i3])
????????????????????????????????????????????????????????????????????????sw = 1;
????????????????????????????????????????????????????????}
????????????????????????????????????????????????}
????????????????????????????????????????}
????????????????????????????????????????if (sw == 0)
????????????????????????????????????????????????s[i1] = 0;
????????????????????????????????}
????????????????????????}
????????????????}
????????????????printf("%d\n", n-m);
????????????????scanf("%d", &n);
????????}
??
????????return 0;
}