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 ...
随机推荐
- selenium python (十四)上传文件的处理
#!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip' #上传过程一般要打开一个系统的windows窗口,从窗口选择本地文件添加 ...
- Linux man命令数字含义
1,用户在shell环境中可以操作的命令或可执行文件 2,系统内核可调用的函数与工具等,即由内核提供的函数. 如open,write之类的(通过这个,可以很方便的查到调用这个函数时需要加什么头文件 ...
- C# 使用Linq递归查询数据库遇到的问题及解决方法
User表通常是我们在写"XX管理系统"项目时必须要用到的,有的情况下人员的分类属于树形结构,就是除了最高层和最低层,中间层都有相对的父和子,设计数据库的时候,我们通常会加一个pa ...
- .Net 学习
.Net 的微型Web框架Nancy ORM工具 Simple Data Ojbective-C 与 swift Xamarin for VisualStudio jQuery 1. 绝对的万金油,核 ...
- css 样式大全
字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...
- 第三百五十八天 how can I 坚持
万事要有度,不要话唠,也不能不说,把握好分寸,今天貌似又说多了. 加了天班,理了个发,还有老爸明天来北京. 还有同学聚会没去,还有金龙让去吃鱼,没去. 还有.小米视频通话还行,能远程控制桌面, 还有, ...
- ems server
自DELPHI XE7始提供企业移动服务,方便移动等设备通过REST+JSON访问中间件提供的服务. EMS (Enterprise Mobility Services企业移动服务) 服务器给EMS客 ...
- UVa11997K Smallest Sums(优先队列)
K Smallest Sums You're given k arrays, each array has k integers. There are kk ways to pick exactly ...
- Android 显示/隐藏 应用图标
PackageManager packageManager = getPackageManager(); ComponentName componentName = new ComponentName ...
- WEB数据挖掘(十三)——关联规则与序列模式(1)
一.Apriori算法简介: Apriori算法是一种挖掘关联规则的频繁项集算法,其核心思想是通过候选集生成和情节的向下封闭检测两个阶段来挖掘频繁项集. Apriori(先验的,推测的)算法应用广泛 ...