1.2.2 Transformations
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了1.2.2 Transformations,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2853字,纯文字阅读大概需要5分钟。
内容图文
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
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 |
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 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5usingnamespace std; 6int main() 7{ 8 freopen("transform.in","r",stdin); 9 freopen("transform.out","w",stdout); 10int n; 11char a[11][11],b[11][11],c; 12bool mar[10]; 13 memset(mar,true,sizeof(mar)); 14 cin>>n; 15 getchar(); 16for(int i=1;i<=n;i++){ 17for(int j=1;j<=n;j++){ 18 cin>>a[i][j]; 19 b[i][n+1-j]=a[i][j]; 20 } 21 getchar(); 22 } 23for(int i=1;i<=n;i++){ 24for(int j=1;j<=n;j++){ 25 cin>>c; 26if(c!=a[n+1-j][i]) mar[1]=false;//9027if(c!=a[n+1-i][n+1-j]) mar[2]=false;//18028if(c!=a[j][n+1-i]) mar[3]=false;//27029if(c!=b[i][j]) mar[4]=false;//水平翻转30if(c!=b[n+1-j][i]) mar[5]=false;//水平翻转+9031if(c!=b[n+1-i][n+1-j]) mar[6]=false;//水平翻转+18032if(c!=b[j][n+1-i]) mar[7]=false;//水平翻转+27033if(c!=a[i][j]) mar[8]=false;//不改变34 } 35 getchar(); 36 } 37int f=0; 38for(int i=1;i<=4;i++){ 39if(mar[i]&&!f) {f=1;cout<<i<<endl;} 40 } 41if((mar[5]||mar[6]||mar[7])&&!f) {f=1;cout<<5<<endl;} 42if(mar[8]&&!f) {f=1;cout<<6<<endl;} 43if(!f) cout<<7<<endl; 44return0; 45 }
原文:http://www.cnblogs.com/shenyw/p/5156045.html
内容总结
以上是互联网集市为您收集整理的1.2.2 Transformations全部内容,希望文章能够帮你解决1.2.2 Transformations所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。