Sunday, June 7, 2015

UVa 253 - Cube painting

// UVa 253 - Cube painting

#include <iostream>
#include <string>
#include <string.h>
using namespace std;

#define max_c 6

int cond[max_c][4] = { { 5, 4, 2, 3 }, { 1, 4, 6, 3 }, { 1, 2, 6, 5 }, { 1, 5, 6, 2 }, { 1, 3, 6, 4 }, { 2, 4, 5, 3 } };

int main() {
	string line;
	while (cin >> line) {
		string sol = "TRUE";
		string a = line.substr(0, 6);
		a = " " + a;
		string b = line.substr(6);
		b = " " + b;
		string c_def[max_c], d_def[max_c];
		for (int i = 0; i < max_c; i++) {
			string c = "", d = "";
			for (int j = 0; j < 4; j++) {
				c = c + a[cond[i][j]];
				d = d + b[cond[i][j]];
			}
			string mc = c, md = d;
			for (int j = 0; j < 4; j++) {
				c = c.substr(1) + c[0];
				if (c < mc)
					mc = c;
				d = d.substr(1) + d[0];
				if (d < md)
					md = d;
			}
			c_def[i] = mc;
			d_def[i] = md;
		}
		bool yet[max_c];
		memset(yet, true, sizeof(yet));
		for (int i = 0; i < max_c; i++) {
			bool found = false;
			for (int j = 0; j < max_c; j++)
				if (c_def[i] == d_def[j] && yet[j]) {
					yet[j] = false;
					found = true;
					break;
				}
			if (!found) {
				sol = "FALSE";
				break;
			}
		}

		cout << sol << endl;
	}
	return 0;
}

No comments:

Post a Comment