UVA 253 (13.08.06)
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)的更多相关文章
- 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 ...
- UVA 10499 (13.08.06)
Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...
- UVA 10025 (13.08.06)
The ? 1 ? 2 ? ... ? n = k problem Theproblem Given the following formula, one can set operators '+ ...
- 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 ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA 465 (13.08.02)
Overflow Write a program that reads an expression consisting of twonon-negative integer and an ope ...
- UVA 10494 (13.08.02)
点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...
- UVA 424 (13.08.02)
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...
- UVA 10106 (13.08.02)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...
随机推荐
- IOS AutoLayout 遍历修改约束
self.cvv2View.hidden = YES; self.periodView.hidden = YES; [self.contentView.constraints enumerateObj ...
- [转] Web前端优化之 Javascript篇
原文链接: http://lunax.info/archives/3099.html Web 前端优化最佳实践之 JavaScript 篇,这部分有 6 条规则,和 CSS 篇 重复的有几条.前端优化 ...
- .gitignore 文件列表
GitHub 有一个十分详细的针对数十种项目及语言的 .gitignore 文件列表,你可以在https://github.com/github/gitignore 找到它.
- NServiceBus-日志
默认的日志 NServiceBus一些有限,固执己见,内置的日志记录. 默认的日��行为如下: 控制台 所有 Info(及以上)消息将被输送到当前的控制台. 错误将会写 ConsoleColor.Re ...
- Jquery 等待ajax返回数据loading控件ShowLoading组件
1.意义 开发项目中,前台的页面要发请求到服务器,服务器响应请求返回数据到前台,这段时间,有可能因为返回的数据量较大导致前台页面出现短暂性的等待,此时如果用户因不知情而乱点击有可能造成逻辑混乱,所以此 ...
- Java 类型信息
<Thinking in Java 4th>第14章 类型信息 运行时类型信息(Run-Time Type Identification)使得你可以在程序运行时发现和使用类型信息. 14. ...
- C#反射实例化类并调用类的方法
反射提高了程序的灵活性和扩展性,降低耦合性,提高自适应能力. 它允许程序创建和控制任何类的对象,无需提前硬编码目标类: SalBLL a = (SalBLL)Assembly.Load("B ...
- esp8266烧写机智云固件方法
转:http://blog.csdn.net/k7arm/article/details/51925941 =====================以下为我转载的文章================ ...
- AVAST 4.8
AVAST专业版注册序列号不能用了就换一个继续注册,接着用序列号:S9665355R9665P1106-YCX4AKKT (2012.5.3)S7592769R8591F1106-ZVDJPMLT ( ...
- LeetCode292:Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...