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<stdio.h>

#define rep(i,n) for(int i=0;i<n;i++)

int main(void){
	while(1){
		int n;
		scanf("%d",&n);
		if(n==0){
			break;
		}
		int sonzai[6][6][6][6][6][6];
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								sonzai[a][b][c][d][e][f]=0;
							}
						}
					}
				}
			}
		}
		
		int now[6];
		for(int q=0;q<n;q++){
			for(int i=0;i<6;i++){
				char str[10];
				scanf("%s",str);
				switch(str[0]){
					case 'C':now[i]=0;break;
					case 'Y':now[i]=1;break;
					case 'R':now[i]=2;break;
					case 'M':now[i]=3;break;
					case 'G':now[i]=4;break;
					case 'B':now[i]=5;break;
				}
			}
			int temp;
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					
					sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
					
					temp=now[2];
					now[2]=now[4];
					now[4]=now[3];
					now[3]=now[1];
					now[1]=temp;
				}
				temp=now[0];
				now[0]=now[2];
				now[2]=now[5];
				now[5]=now[3];
				now[3]=temp;
			}
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			
			for(int j=0;j<4;j++){
					
				sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
				
				temp=now[2];
				now[2]=now[4];
				now[4]=now[3];
				now[3]=now[1];
				now[1]=temp;
			}
			
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			temp=now[0];
			now[0]=now[1];
			now[1]=now[5];
			now[5]=now[4];
			now[4]=temp;
			
			for(int j=0;j<4;j++){
					
				sonzai[now[0]][now[1]][now[2]][now[3]][now[4]][now[5]]=1;
				
				temp=now[2];
				now[2]=now[4];
				now[4]=now[3];
				now[3]=now[1];
				now[1]=temp;
			}
		}
		int cont=0;
		rep(a,6){
			rep(b,6){
				rep(c,6){
					rep(d,6){
						rep(e,6){
							rep(f,6){
								cont+=sonzai[a][b][c][d][e][f];
							}
						}
					}
				}
			}
		}
		printf("%d\n",n-cont/24);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int N;
int main()
{
	while(true){
		scanf("%d",&N);
		if(N==0)return 0;
		int X[6];
		set<int>S;
		for(int i=0;i<N;i++){
			for(int j=0;j<6;j++){
				string SS;
				cin >> SS;
				if(SS=="Cyan")X[j]=0;
				if(SS=="Yellow")X[j]=1;
				if(SS=="Red")X[j]=2;
				if(SS=="Magenta")X[j]=3;
				if(SS=="Green")X[j]=4;
				if(SS=="Blue")X[j]=5;
			}
			if(X[0]==0||X[5]==0){
				int minc=7,minci;
				for(int i=1;i<5;i++){
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==1){
					sum=X[1]+X[2]*6+X[3]*36+X[4]*216;
				}
				if(minci==2){
					sum=X[2]+X[3]*6+X[4]*36+X[1]*216;
				}
				if(minci==3){
					sum=X[3]+X[4]*6+X[1]*36+X[2]*216;
				}
				if(minci==4){
					sum=X[4]+X[1]*6+X[2]*36+X[3]*216;
				}
				S.insert(sum);
			}
			if(X[1]==0||X[4]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==1||i==4)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==0){
					sum=X[0]+X[2]*6+X[5]*36+X[3]*216;
				}
				if(minci==2){
					sum=X[2]+X[5]*6+X[3]*36+X[0]*216;
				}
				if(minci==5){
					sum=X[5]+X[3]*6+X[0]*36+X[2]*216;
				}
				if(minci==3){
					sum=X[3]+X[0]*6+X[2]*36+X[5]*216;
				}
				S.insert(sum);
			}
			if(X[2]==0||X[3]==0){
				int minc=7,minci;
				for(int i=0;i<6;i++){
					if(i==2||i==3)continue;
					if(minc>X[i]){
						minci=i;
						minc=X[i];
					}
				}
				int sum=0;
				if(minci==4){
					sum=X[4]+X[0]*6+X[1]*36+X[5]*216;
				}
				if(minci==0){
					sum=X[0]+X[1]*6+X[5]*36+X[4]*216;
				}
				if(minci==1){
					sum=X[1]+X[5]*6+X[4]*36+X[0]*216;
				}
				if(minci==5){
					sum=X[5]+X[4]*6+X[0]*36+X[1]*216;
				}
				S.insert(sum);
			}
		}
		printf("%d\n",N-(int)S.size());
	}
}

C++: 
// Trouble in Shinagawa's Artifacts
//  URL: http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=0198&lang=jp

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>

#define FOREACH( TYPE, TARGET, IT ) \
	for( (TYPE)::iterator IT = (TARGET).begin(); IT != (TARGET).end(); ++(IT) )

// Ö
std::vector <int> rotate_h( std::vector <int> box );
std::vector <int> rotate_v( std::vector <int> box );

// ¡Éñ]³¹éÖ
std::vector <int> rotate_h( std::vector <int> box )
{
	// ¡ñ]
	// c1, c2, c3, c4, c5, c6 : default
	// c3, c2, c6, c1, c5, c4
	
	int tmp	= box[0];
	box[0]	= box[2];
	box[2]	= box[5];
	box[5]	= box[3];
	box[3]	= tmp;

	return box;

}

// cÉñ]³¹éÖ
std::vector <int> rotate_v( std::vector <int> box )
{
	// cñ]
	// c1, c2, c3, c4, c5, c6 : default
	// c5, c1, c3, c4, c6, c2

	int tmp = box[0];
	box[0] = box[4];
	box[4] = box[5];
	box[5] = box[1];
	box[1] = tmp;

	return box;

}

// Gg[|Cg
int main()
{
	// §ûÌÌ6ÊðyLÅFt¯µ½àÌðìiÆµÄoWµ½
	// §ûÌðñ]³¹éÆ¯¶gÝí¹ÉÈÁÄµÜ¤±ÆÉCªt¢½
	// d¡ð³­µ½Æ«ÇÁÅ½Âìè¼·Kvª é©ßé



	// Ï
	int n;
	int answer;
	char color[32];
	std::vector <int> box( 6, 0 );
	std::set < std::vector <int> > table;

	while( 1 )
	{
		// ú»
		answer = 0;
		table.clear();
		for( int i = 0; i < 6; ++i )
		{
			box[i] = 0;
		}

		// üÍ
		std::fflush( stdin );
		std::scanf( "%d", &n );

		// üÍÌIíèF[ÐÆÂ
		if( n == 0 ) break;

		// nÌ¾¯ÇÝÞ
		for( int i = 0; i < n; ++i )
		{
			std::fflush( stdin );

			// FîñðüÍ
			for( int j = 0; j < 6; ++j )
			{
				std::scanf( "%s", color );

				// µ¢â·¢æ¤É¶ñ¨®ÉÏ·
				// F: Red, Yellow, Blue, Magenta, Green, Cyan
				if( std::strcmp( "Red", color ) == 0 )
					box[j] = 1;
				else if( std::strcmp( "Yellow", color ) == 0 )
					box[j] = 2;
				else if( std::strcmp( "Blue", color ) == 0 )
					box[j] = 3;
				else if( std::strcmp( "Magenta", color ) == 0 )
					box[j] = 4;
				else if( std::strcmp( "Green", color ) == 0 )
					box[j] = 5;
				else if( std::strcmp( "Cyan", color ) == 0 )
					box[j] = 6;
			}

			// insertÌOÉ¯¶àÌªÈ¢©T·
			// ¯¶àÌª Á½çJEg
			if( table.find( box ) != table.end() )
			{
				++answer;
				continue;
			}

			// insertµÄ¨­
			// ¡¨cx3ð4ñ
			for( int j = 0; j < 4; ++j )
			{
				if( j > 0 )
				{
					box = rotate_h( box );
				}
				table.insert( box );
				
				// c
				for( int k = 0; k < 4; ++k )
				{
					box = rotate_v( box );
					table.insert( box );
				}
			}
		}

		// debug
		std::printf( "%d\n", answer );

	}

} // main()