Transformations


/*
ID: tausiq11
PROG: transform
LANG: C++
*/

#include <stdio.h>

int n;
char set1 [10] [12];
char set2 [10] [12];
char copy [10] [12];

bool check (char x [10] [12], char y [10] [12] )
{
    bool flag = true;

    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            if ( x [i] [j] != y [i] [j] ) {
                flag = false;
                i = j = n;
            }
        }
    }

    return flag;
}

bool _90degree ()
{
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            copy [j] [n - 1 - i] = set1 [i] [j];
    }

    if ( check (copy, set2) )
        return true;

    return false;
}

bool _180degree ()
{
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            copy [n - 1 - i] [n - 1 - j] = set1 [i] [j];
    }

    if ( check (copy, set2) )
        return true;

    return false;
}

bool _270degree ()
{
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            copy [n - 1 - j] [i] = set1 [i] [j];
    }

    if ( check (copy, set2) )
        return true;

    return false;
}

bool reflection ()
{
    for ( int i = 0; i < n; i++ ) {
        for ( int j = n - 1; j >= 0; j-- )
            copy [i] [n - 1 - j] = set1 [i] [j];
    }

    if ( check (copy, set2) )
        return true;

    return false;
}

bool combination ()
{
    char temp [10] [12];

    // _90 degree
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            temp [j] [n - 1 - i] = copy [i] [j];
    }

    if ( check (temp, set2) )
        return true;

    // _180 degree
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            temp [n - 1 - i] [n - 1 - j] = copy [i] [j];
    }

    if ( check (temp, set2) )
        return true;

    // _270 degree
    for ( int i = n - 1; i >= 0; i-- ) {
        for ( int j = 0; j < n; j++ )
            temp [n - 1 - i] [n - 1 - j] = copy [i] [j];
    }

    if ( check (temp, set2) )
        return true;

    return false;
}

bool no_change ()
{
    if ( check (set1, set2) )
        return true;

    return false;
}

int main ()
{
    freopen ("transform.in", "r", stdin);
	freopen ("transform.out", "w", stdout);

    scanf ("%d", &n);
    getchar ();

    for ( int i = 0; i < n; i++ )
        scanf ("%s", set1 [i]);
    for ( int i = 0; i < n; i++ )
        scanf ("%s", set2 [i]);

    if ( _90degree () )
        printf ("1\n");

    else if ( _180degree () )
        printf ("2\n");

    else if ( _270degree () )
        printf ("3\n");

    else if ( reflection () )
        printf ("4\n");

    else if ( combination () )
        printf ("5\n");

    else if ( no_change () )
        printf ("6\n");

    else
        printf ("7\n");

    return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s