Cube painting 

We have a machine for painting cubes. It is supplied withthree different colors: blue,red and green. Each face of the cube gets oneof these colors. The cube's faces arenumbered as in Figure 1.

Figure 1.

Since a cube has 6 faces, our machine canpaint a face-numbered cube in different ways. When ignoring the face-numbers,the number of different paintings ismuch 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 ab, r,or g. The character ( ) fromthe left gives the color of facei. For example,Figure 2 is a picture of rbgggr and Figure 3corresponds torggbgr. Notice that bothcubes are painted in the same way: byrotating it around the vertical axis by 90 , theone changes into the other.

Input

The input of your program is a textfile thatends with the standard end-of-file marker.Each line is a string of 12 characters.The first 6 characters of this string are therepresentation of a painted cube, theremaining 6 characters give you the representationof another cube. Your program determines whetherthese two cubes are painted in thesame way, that is, whether by any combinationof rotations one can be turned into theother. (Reflections are not allowed.)

Output

The output is a file of boolean.For each line of input, output contains TRUE if thesecond half can be obtained from the firsthalf by rotation as describes above,FALSEotherwise.

Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE

题意: 一个如图所示的正方体, 每面标了数字以及印上了某字符

给出按原始顺序读取的(即按数字从小到大读)字符串以及我们需要的目标字符串

通过旋转正方体, 再读取这个正方体上的字符串 判断是否与我们需要的字符串顺序相同~

做法: 设定一份初始的顺序, 我这里是按某面朝上来份的, 数组为rot

而后, 每一种面朝上时, 围绕一根垂直顶面的轴, 都可以旋转四次~(在我的代码中是用for循环四次~)

每次旋转完要判断, 根据标记输出~TRUE or FALSE

AC代码:

#include<stdio.h>
#include<string.h> int rot[6][6] = {{1,2,3,4,5,6}, {2,6,3,4,1,5}, {6,5,3,4,2,1}, {5,1,3,4,6,2}, {3,1,2,5,6,4}, {4,6,2,5,1,3}}; int main() {
char oringe[7];
char tmp[7];
char change[7];
char str[13];
int pos;
while(gets(str) != NULL) { int mark = 0;
for(int i = 0; i < 6; i++)
oringe[i] = str[i];
oringe[6] = '\0'; pos = 0;
for(int i = 6; i < 12; i++)
change[pos++] = str[i];
change[pos] = '\0'; for(int i = 0; i < 6; i++) {
pos = 0;
for(int j = 0; j < 6; j++)
tmp[pos++] = oringe[rot[i][j]-1];
tmp[pos] = '\0';
char cht;
for(int j = 0; j < 4; j++) {
cht = tmp[1];
tmp[1] = tmp[2];
tmp[2] = tmp[4];
tmp[4] = tmp[3];
tmp[3] = cht;
if(strcmp(change, tmp) == 0) {
mark = 1;
break;
}
}
} if(mark)
printf("TRUE\n");
else
printf("FALSE\n");
}
return 0;
}

UVA 253 (13.08.06)的更多相关文章

  1. UVA 573 (13.08.06)

     The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can cl ...

  2. UVA 10499 (13.08.06)

    Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...

  3. UVA 10025 (13.08.06)

     The ? 1 ? 2 ? ... ? n = k problem  Theproblem Given the following formula, one can set operators '+ ...

  4. UVA 10790 (13.08.06)

     How Many Points of Intersection?  We have two rows. There are a dots on the toprow andb dots on the ...

  5. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  6. UVA 465 (13.08.02)

     Overflow  Write a program that reads an expression consisting of twonon-negative integer and an ope ...

  7. UVA 10494 (13.08.02)

    点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...

  8. UVA 424 (13.08.02)

     Integer Inquiry  One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...

  9. UVA 10106 (13.08.02)

     Product  The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...

随机推荐

  1. MAC OSX 驱动操作

    mac ox系统的驱动安装常规操作:下载到 *.kext 的驱动以后,都可以直接把它拖到 /System/Library/Extensions/ 下替换掉原来的文件.替换了以后,还需要修复权限才能够正 ...

  2. php获取网站根目录

    php获取网站根目录方法一:<?phpdefine("WWWROOT",str_ireplace(str_replace("/","\\&quo ...

  3. 【剑指offer 面试题34】丑数

    只包含因子2.3.5的数称作丑数. #include <iostream> #include <vector> using namespace std; int GetUgly ...

  4. python2.7系列安装失败的办法

    在windows系统上安装python时出现"there is a problem with your Windows installer package. A program run as ...

  5. 说说Python 中的文件操作 和 目录操作

    我们知道,文件名.目录名和链接名都是用一个字符串作为其标识符的,但是给我们一个标识符,我们该如何确定它所指的到底是常规文件文件名.目录名还是链接名呢?这时,我们可以使用os.path模块提供的isfi ...

  6. JavaScript之Object

    两种简单的JavaScript中定义对象的方式: 在JavaScript中,可以动态添加对象的属性,也可以动态删除对象的属性. var object=new object(); //alert(obj ...

  7. 第二百三十一天 how can I 坚持

    哎,蛋疼的一天,一点破问题搞了一下午,还没搞利索. 他们要组织出去玩,我没有参加啊,随便找了个借口. 博客园的字体怎么变小了呢,看着好难受啊,昨天传照片传的? 睡觉.外边下着雨呢,喜欢下雨的夏天还有下 ...

  8. 第二百二十八天 how can I 坚持

    hibernate 还有好多不会搞啊,本来很简单的东西,没用过就不会. 今天... 只是感觉很累,昨天爬山爬的,不知道该写点啥了,买的羽绒服到了,还行吧,凑合穿吧. 睡觉了.今天貌似又发脾气了.哎.. ...

  9. 借助LVS+Keepalived实现负载均衡(转)

    原文:http://www.cnblogs.com/edisonchou/p/4281978.html 一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务 ...

  10. cocos2d-x使用python创建vs模板

    cocos2d-x 2.2推荐使用create_project.py创建工程,所有的平台都可以通过这个python文件创建工程.这个文件位置在源码cocos2d-x-2.2.2\tools\proje ...