UVa : 11349 (Symmetric Matrix)



// http://uva.onlinejudge.org/external/113/11349.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long
using namespace std;

LL mat [100 + 3] [100 + 3];
bool symmetric;
int dimen;

void is_symmetric ()
{
    if ( !symmetric ) return;

    for ( int i = 0; i < dimen; i++ ) {
        for ( int j = 0; j < dimen; j++ ) {
            if ( mat [i] [j] != mat [dimen - 1 - i] [dimen - 1 - j] ) { symmetric = false; return; }
        }
    }
}

int main ()
{
    int testCase;
    scanf ("%d", &testCase);
    int cases = 0;

    while ( testCase-- ) {

        symmetric = true;

        char ch [10];
        getchar ();
        gets (ch);
        sscanf (ch, "%c = %d", &ch [0], &dimen);

        for ( int i = 0; i < dimen; i++ ) {
            for ( int j = 0; j < dimen; j++ ) {
                cin >> mat [i] [j];
                if ( mat [i] [j] < 0 ) symmetric = false;
            }
        }

        printf("Test #%d: ", ++cases);

        if ( !symmetric ) { printf ("Non-symmetric.\n"); continue; }

        is_symmetric ();

        if ( symmetric ) printf ("Symmetric.\n");
        else printf ("Non-symmetric.\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE

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