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>
#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;
}

C++: #include<iostream>
#include<string>

using namespace std;

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		int check[6][6][6][6][6][6]={0};
		
		for(int i=0;i<n;i++){
			int s[7];
			for(int j=1;j<=6;j++){
				string a;
				cin>>a;
				
				switch(a[0]){
					case 'C':s[j]=0;break;
					case 'Y':s[j]=1;break;
					case 'R':s[j]=2;break;
					case 'M':s[j]=3;break;
					case 'G':s[j]=4;break;
					case 'B':s[j]=5;break;
				}
			}
			int bin;
			for(int i=0;i<4;i++){
				bin=s[2];
				s[2]=s[3];
				s[3]=s[5];
				s[5]=s[4];
				s[4]=bin;
				for(int j=0;j<4;j++){
					bin=s[1];
					s[1]=s[5];
					s[5]=s[6];
					s[6]=s[2];
					s[2]=bin;
					
					check[s[1]][s[2]][s[3]][s[4]][s[5]][s[6]]=1;
				}
			}
		}
		int cont=0;
		for(int a=0;a<6;a++)
		for(int b=0;b<6;b++)
		for(int c=0;c<6;c++)
		for(int d=0;d<6;d++)
		for(int e=0;e<6;e++)
		for(int f=0;f<6;f++)
		cont+=check[a][b][c][d][e][f];
		
		printf("%d\n",n-(cont/16));
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n;

bool judge(vector<string>a, vector<string>b){
  int ret = 1, j;
  rep(i, 6){
    for(j = 0; j < 6; j++) if(a[i] == b[j]) break;
    if(a[5-i] != b[5-j]) ret = 0;
  }

  /*  rep(i, 6) cout << a[i] << " "; puts("");
  rep(i, 6) cout << b[i] << " "; puts("");
  cout << ret << endl;*/
  return ret;
}

int main(){
  while(scanf("%d", &n) && n){

    vector<vector<string> >c(n, vector<string>(6));
    rep(i, n) rep(j, 6) cin >> c[i][j];

    vector<int>f(n, 0);
    rep(i, n){
      if(f[i]) continue;
      REP(j, i+1, n) if(judge(c[i], c[j])) f[j] = 1;
    }
    int res = 0;
    rep(i, n) if(f[i]) res++;
    printf("%d\n", res);
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
string color[6] =  {"Cyan", "Yellow", "Red", "Magenta", "Green", "Blue"};
int* south(int c[6]) {
	int buf = c[0];
	c[0] = c[1];
	c[1] = c[5];
	c[5] = c[4];
	c[4] = buf;
	return c;
}
int* east(int c[6]) {
	int buf = c[0];
	c[0] = c[2];
	c[2] = c[5];
	c[5] = c[3];
	c[3] = buf;
	return c;
}
int* round(int c[6]) {
	int buf = c[1];
	c[1] = c[2];
	c[2] = c[4];
	c[4] = c[3];
	c[3] = buf;
	return c;
}
bool check(int d1[6], int d2[6]) {
	rep(i,6) {
		if(i%2)d1 = south(d1);
		else d1 = east(d1);
		rep(j,4) {
			d1 = round(d1);
			bool f = 1;
			rep(k,6) {
				if(d1[k] != d2[k]) {
					f = 0;
					break;
				}
			}	
			if(f) return true;
		}
	}
	return false;
}
int main(){
	int n, d[30][6] = {};
	string s;
	while(cin >> n, n) {
		rep(i,n) {
			rep(j,6) {
				cin >> s;
				rep(k,6) {
					if(color[k] == s) d[i][j] = k;
				}
			}
		}
		int a[30];
		bool used[30] = {};
		rep(i,n) a[i] = i;
		rep(i,n) {
			rep2(j,i+1,n) {
				if(check(d[i],d[j])) {
					a[j] = i;
				}
			}
		}
		rep(i,n) {
			int x = i;
			while(a[x]!=x) {
				a[x] = a[a[x]];
				x = a[x];
			}
		}
		rep(i,n) used[a[i]] = true;
		int ret = 0;
		rep(i,n) {
			if(!used[i]) ret++;
		}
		cout << ret << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
    int i,j,n,k[100],count=0;
    char c1[100],c2[100],c3[100],c4[100],c5[100],c6[100];
    for(j=0;j<100;j++){
    cin>>n;
    for(i=0;i<n;i++){
        cin>>c1>>c2>>c3>>c4>>c5>>c6;
        k[i]=c1[i]>>c2[i]>>c3[i]>>c4[i]>>c5[i]>>c6[i];
    }
        if(k[i]==k[i]){
            count++;
        }
        cout<<count<<endl;
        count=0;
        if(c1==0){
            break;
        }
}
    
    return 0;
}