USACO 1.2-Transformations

/*
ID: m1590291
TASK: transform
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#define MAX 20
using namespace std;
int n;
char a[MAX][MAX],b[MAX][MAX];

bool check()    //检查是否相等
{
    bool flag=true;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			if(a[i][j]!=b[i][j])
                return false;
    return true;
}
void to90()    //旋转90度
{
    char tmp[MAX][MAX];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			tmp[j][n-i-1]=a[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			a[i][j]=tmp[i][j];
}
void Ref()    //中央铅垂线翻转
{
	char tmp[MAX][MAX];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			tmp[i][n-j-1]=a[i][j];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			a[i][j]=tmp[i][j];
}
int main()
{
    ifstream fin ("transform.in");
    ofstream fout ("transform.out");
    while(fin>>n)
    {
        int flag=1,ans=100;
        if(n<1 || n>10) break;

        for(int i=0;i<n;i++)    fin>>a[i];
        for(int i=0;i<n;i++)    fin>>b[i];

        for(int i=1;i<4;i++){
            to90();
            if(check() == true)
                ans=min(ans,i);
        }
        to90();  //再次旋转90度,使图形变回原样
        if(ans>4){
            Ref();
            if(check() == true)
                ans=4;
            else{
                for(int i=1;i<4;i++){
                    to90();
                    if(check() == true)
                        ans=5;
                }
            }
        }
        if(ans>5){
            if(check() == true)
                ans=6;
            else
                ans=7;
        }
        fout<<ans<<endl;
    }
    return 0;
}


posted on 2016-04-04 23:02  Jstyle  阅读(126)  评论(0编辑  收藏  举报

导航