- #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.
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
---------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<string.h>
char s[15][15]={0},p[15][15],q[15][15]={0};
int n;
int check1(){
int i,j;
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
p[i][j]=s[n-j-1][i];
if(memcmp(q,p,sizeof(s))==0) return 1;
return 0;
}
int check2(){
int i,j;
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
p[i][j]=s[n-i-1][n-j-1];
if(memcmp(q,p,sizeof(s))==0) return 1;
return 0;
}
int check3(){
int i,j;
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
p[i][j]=s[j][n-i-1];
if(memcmp(q,p,sizeof(s))==0) return 1;
return 0;
}
int check4(){
int i,j;
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
p[i][j]=s[i][n-j-1];
if(memcmp(q,p,sizeof(s))==0) return 1;
return 0;
}
int check5(){
int i,j;
check4();
memcpy(s,p,sizeof(s));
if(check1() || check2() || check3()) return 1;
return 0;
}
void Pt(){
int i;
for(i=0;i<n;i++)
puts(p[i]);
puts(".");
}
int main(){
int i,t;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%s",s[i]);
//check4(),Pt();
for(i=0;i<n;i++)
scanf("%s",q[i]);
t=memcmp(s,q,sizeof(s));
if(check1()){
puts("1");
return 0;
}
if(check2()){
puts("2");
return 0;
}
if(check3()){
puts("3");
return 0;
}
if(check4()){
puts("4");
return 0;
}
if(check5()){
puts("5");
return 0;
}
if(t==0){
puts("6");
return 0;
}
puts("7");
}
沒有留言:
張貼留言