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++: 
// 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>

// Ö
std::vector <int> rotate( std::vector <int> box, int a, int b, int c, int d );
std::vector <int> rotate_x( std::vector <int> box );
std::vector <int> rotate_y( std::vector <int> box );
std::vector <int> rotate_z( std::vector <int> box );

// ñ]
std::vector <int> rotate( std::vector <int> box, int a, int b, int c, int d )
{
	int tmp = box[a];
	box[a] = box[b];
	box[b] = box[c];
	box[c] = box[d];
	box[d] = tmp;

	return box;
}

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

	return rotate( box, 0, 4, 5, 1 );

}


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

	return rotate( box, 1, 3, 4, 2 );

}

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

	return rotate( box, 0, 2 ,5 ,3 );

}

// Gg[|Cg
int main()
{

	// Ï
	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( "Grdeen", 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 k = 0; k < 6; ++k )
			{
				// x
				for( int j = 0; j < 4; ++j )
				{
					box = rotate_x( box );
					table.insert( box );
				}

				if( k % 2 == 0 )
				{
					box = rotate_y( box );
				}
				else
				{
					box = rotate_z( box );
				}

			}

		}

		// oÍ
		std::printf( "%d\n", answer );

	}

} // main()

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 < 3 && 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;
}

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

using namespace std;

void rotx(vector<int> &cube)
{
	vector<int> tmp=cube;
	cube[0]=tmp[3];
	cube[1]=tmp[1];
	cube[2]=tmp[0];
	cube[3]=tmp[5];
	cube[4]=tmp[4];
	cube[5]=tmp[2];
}

void roty(vector<int> &cube)
{
	vector<int> tmp=cube;
	cube[0]=tmp[1];
	cube[1]=tmp[5];
	cube[2]=tmp[2];
	cube[3]=tmp[3];
	cube[4]=tmp[0];
	cube[5]=tmp[4];
}

int main()
{
	map<string,int> mp;
	mp["Red"]=0;
	mp["Yellow"]=1;
	mp["Blue"]=2;
	mp["Magenta"]=3;
	mp["Green"]=4;
	mp["Cyan"]=5;

	for(int n;cin>>n,n;){
		vector< vector<int> > cube(n);
		for(int i=0;i<n;i++){
			vector<int> c(6);
			string s;
			for(int j=0;j<6;j++)	cin>>s,c[j]=mp[s];

			vector<int> cmax=c;
			for(int x=0;x<4;x++,rotx(c))
				for(int y=0;y<4;y++,roty(c))cmax=max(cmax,c);
			roty(c);
			rotx(c);
			for(int y=0;y<4;y++,roty(c))	cmax=max(cmax,c);
			rotx(c);
			rotx(c);
			for(int y=0;y<4;y++,roty(c))	cmax=max(cmax,c);

			cube[i]=cmax;
		}
		sort(cube.begin(),cube.end());
		cube.erase(unique(cube.begin(),cube.end()),cube.end());
		cout<<n-cube.size()<<endl;
	}

	return 0;
}