transformations

Transformations</font></b>
</center>

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: </p>

  • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees. </li>
  • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees. </li>
  • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.</li>
  • #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).</li>
  • #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3). </li>
  • #6: No Change: The original pattern was not changed. </li>
  • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods. </li></ul>

    In the case that more than one transform could have been used, choose the one with the minimum number above. </p>

    PROGRAM NAME: transform</h3>

    INPUT FORMAT</h3>
    Line 1: </td> A single integer, N </td> </tr>
    Line 2..N+1: </td> N lines of N characters (each either `@' or `-'); this is the square before transformation</td> </tr>
    Line N+2..2*N+1: </td> N lines of N characters (each either `@' or `-'); this is the square after transformation</td> </tr> </tbody></table>

    SAMPLE INPUT (file transform.in) </h3>
    3 @-@ --- @@- @-@ @-- --@ </pre>

    OUTPUT FORMAT</h3> 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)</h3>
    1
    /*
    ID:hejiek1
    LANG: C
    TASK:transform
    */
    #include
    #include
    #include
    int input(char ***pre,char***aft)
    {
    int n,i;
    FILE *fp=fopen("transform.in","r");
    fscanf(fp,"%d",&n);
    char **p1=(char**)malloc(n*sizeof(char*));
    char **p2=(char**)malloc(n*sizeof(char*));
    for(i=0;i {
    p1[i]=(char*)malloc(n*sizeof(char));
    p2[i]=(char*)malloc(n*sizeof(char));
    }
    for(i=0;i fscanf(fp,"%s",p1[i]);
    for(i=0;i fscanf(fp,"%s",p2[i]);
    (*pre)=p1;
    (*aft)=p2;
    return n;
    }
    int transforms(int n,char **pre,char**aft)
    {
    int flag[7],i,j,tmp=1,k=0;
    memset(flag,1,sizeof(flag));
    for(i=0;i for(j=0;j {
    if(pre[i][j]!=aft[j][n-i-1])
    flag[1]=0;
    if(pre[i][j]!=aft[n-i-1][n-j-1])
    flag[2]=0;
    if(pre[i][j]!=aft[n-j-1][i])
    flag[3]=0;
    if(pre[i][j]!=aft[i][n-j-1])
    flag[4]=0;
    if(pre[i][j]!=aft[i][j]);
    flag[6]=0;
    }
    for(i=1;i<5;i++)
    if(flag[i])
    return i;
    if(flag[6])
    return 6;
    return 0;
    }
    int combination(int n,char**pre,char**aft)
    {
    int flag,i,j;
    char **tmp=(char**)malloc(n*sizeof(char*));
    for(i=0;i tmp[i]=(char*)malloc(n*sizeof(char));
    for(i=0;i for(j=0;j tmp[i][j]=aft[i][n-j-1];
    flag=transforms(n,pre,tmp);
    if(flag<=3&&flag>=1)
    return 5;
    for(i=0;i for(j=0;j tmp[i][j]=aft[n-i-1][j];
    flag=transforms(n,pre,tmp);
    if(flag<=3&&flag>=1)
    return 5;
    return -1;
    }
    void output(int num)
    {
    FILE *fp=fopen("transform.out","w");
    if(num!=-1)
    fprintf(fp,"%dn",num);
    else
    fprintf(fp,"7n",num);
    }
    int main (int argc, char const* argv[]) {
    int flag=0,n;
    char **pre=NULL,**aft=NULL;
    n=input(&pre,&aft);
    flag=transforms(n,pre,aft);
    if(!flag)
    flag=combination(n,pre,aft);
    output(flag);
    return 0;
    }
    </pre></div>