UVa253

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube‘s faces are numbered as in Figure 1.

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in  different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a br, or g. The  character (  ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90  , the one changes into the other.

 

Input

The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)

Output

The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.

Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE

题目:

给出两个正方体各面的染色情况(仅能染红、绿、蓝),判断这两个正方体是否属于同一染色方式(以正方体可以通过翻转变为另一个)。

输入:

多组数据,每组数据是一长为12的字符串,前6个字符代表第一个正方体各面的染色方式----r红、g绿、b蓝。

输出:

每组输入输出“对”或者“不对”。

分析:

注意到,如果正方体的三对对面的染色状况都对应相同的话,两个正方体的染色状况也就相同了。采用string类,将两正方体各自的三对对面染色字母的ASCII码和分别计算出来。如果三对之间形成一一映射即满足同一染色。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <string>
 5 using namespace std;
 6 int main(){
 7     string str;
 8     while(cin >> str){
 9         string a1,a2,a3,b1,b2,b3;
10         a1 = str[0] + str[5];
11         a2 = str[1] + str[4];
12         a3 = str[2] + str[3];
13         b1 = str[6] + str[11];
14         b2 = str[7] + str[10];
15         b3 = str[8] + str[9];
16         if((a1 == b1 || a1 == b2 || a1 == b3)
17            && (a2 == b1 || a2 == b2 || a2 == b3)
18            && (a3 == b1 || a3 == b2 || a3 == b3))
19             if((b1 == a1 || b1 == a2 || b1 == a3)
20                && (b2 == a1 || b2 == a2 || b2 == a3)
21                && (b3 == a1 || b3 == a2 || b3 == a3))
22                 printf("TRUE\n");
23             else
24                 printf("FALSE\n");
25         else
26             printf("FALSE\n");
27     }
28     return 0;
29 }

时间: 2024-12-15 06:57:08

UVa253的相关文章

UVA253 Cube painting【置换】

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1. ????Since a cube has 6 faces, our machine can paint a

uva253 Cube painting(UVA - 253)

题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相同的面并且他们的对面相等那么继续寻找,直到三个面都能找到相对立的面 ③如果有一个面没有找到相等的面或者相等的对面之类的那么就break循环然后直接判断FALSE如果三个面都能满足上述条件,那么就是TRUE 代码 #include <bits/stdc++.h> using namespace st

UVa 253 骰子涂色

https://vjudge.net/problem/UVA-253 题意:输入两个骰子的六面颜色,判断是否等价. 思路:我最想到的是暴力,不过一直错,也不知道哪里错了.第二种方法就是在一个骰子里出现的一对颜色在第二个骰子也有,只要三对颜色都匹配成功,那么就是等价的. 1 #include<iostream> 2 #include<string> 3 #include<cstring> 4 using namespace std; 5 6 char str[20]; 7

2019年8月做题记录

codeforces1199C codeforces1198B codeforces1197A codeforces1197B codeforces1197C codeforces1197D codeforces1198C codeforces1201A codeforces1201B codeforces1201C codeforces1189A codeforces1189B codeforces1189C codeforces1189D1 codeforces1189E codeforce

算法竞赛入门经典 第四章

[√ ] UVA1339 古老的密码 Ancient Cipher [√ ] UVA489 刽子手的游戏 Hangman Judge [√ ] UVA133 救济金发放 The Dole Queue [√ ] UVA213 信息解码 Message Decoding [√ ] UVA512 追踪电子表格中的单元格 Spreadsheet Tracking [√ ] UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)