1.2.2 Transformations
2016-01-24 21:38
141 查看
A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:
#1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
#2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
#3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
#4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
#5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
#6: No Change: The original pattern was not changed.
#7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
In the case that more than one transform could have been used, choose the one with the minimum number above.
PROGRAM NAME: transform
INPUT FORMAT
SAMPLE INPUT (file transform.in)
3
@-@
---
@@-
@-@
@--
--@
OUTPUT FORMAT
A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.
SAMPLE OUTPUT (file transform.out)
1
代码:
#1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
#2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
#3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
#4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
#5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
#6: No Change: The original pattern was not changed.
#7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
In the case that more than one transform could have been used, choose the one with the minimum number above.
PROGRAM NAME: transform
INPUT FORMAT
Line 1: | A single integer, N |
Line 2..N+1: | N lines of N characters (each either `@' or `-'); this is the square before transformation |
Line N+2..2*N+1: | N lines of N characters (each either `@' or `-'); this is the square after transformation |
3
@-@
---
@@-
@-@
@--
--@
OUTPUT FORMAT
A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.
SAMPLE OUTPUT (file transform.out)
1
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { freopen("transform.in","r",stdin); freopen("transform.out","w",stdout); int n; char a[11][11],b[11][11],c; bool mar[10]; memset(mar,true,sizeof(mar)); cin>>n; getchar(); for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; b[i][n+1-j]=a[i][j]; } getchar(); } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>c; if(c!=a[n+1-j][i]) mar[1]=false;//90 if(c!=a[n+1-i][n+1-j]) mar[2]=false;//180 if(c!=a[j][n+1-i]) mar[3]=false;//270 if(c!=b[i][j]) mar[4]=false;//水平翻转 if(c!=b[n+1-j][i]) mar[5]=false;//水平翻转+90 if(c!=b[n+1-i][n+1-j]) mar[6]=false;//水平翻转+180 if(c!=b[j][n+1-i]) mar[7]=false;//水平翻转+270 if(c!=a[i][j]) mar[8]=false;//不改变 } getchar(); } int f=0; for(int i=1;i<=4;i++){ if(mar[i]&&!f) {f=1;cout<<i<<endl;} } if((mar[5]||mar[6]||mar[7])&&!f) {f=1;cout<<5<<endl;} if(mar[8]&&!f) {f=1;cout<<6<<endl;} if(!f) cout<<7<<endl; return 0; }
相关文章推荐
- spring对JDBC整合的时候,要注意自己写一个映射,继承RowMapper,查询的时候会用到,将返回的ResultSet一条对应一个Employee对象。
- SPI、I2C、UART(转)
- spojD_query【主席树】统计区间内不重复数的个数
- 查找链表倒数第K个节点
- hdu4857 逃生 (优先级队列 + 拓扑排序)
- java多线程实现方式
- C++变量内存分配及类型修饰符
- Eclipse 安装Hibernate插件
- 四连通与八连通
- 高富帅
- junit(四)
- 第三周总结
- Redis能干啥?细看11种Web应用场景
- transform 容器元素变换函数
- java中获取路径中的空格处理(%20)问题
- LFU(Least Frequently Used) C++ 实现
- python第一步:安装ipython
- Java 2015 年最热门的 10 篇技术文章
- 《笨办法学Python》 第22课手记
- android_重写button样式