USACO-Section1.2 Transformations

Transformations

按顺序执行各布操作并判断即可,其中旋转部分代码可复用。
代码如下:

/*
ID: xhzdcyy1
PROB: transform
LANG: C++         
*/
#include <iostream>
#include <fstream>
#include <string>
#include<map>
#define cin fin
#define cout fout 
using namespace std;
int a[10][10];
int b[10][10];
int c[10][10];
int n;
void fun1(){
	int d[10][10];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			d[j][n-i-1]=c[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			c[i][j]=d[i][j];
		}
	}
	return;
}

bool check1(){
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(c[i][j]!=b[i][j]) return false;
		}
	}
	return true;
}

int main()
{
	ofstream fout ("transform.out");
	ifstream fin ("transform.in");
	char tmp;

	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>tmp;
			if(tmp=='@') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>tmp;
			if(tmp=='@') b[i][j]=0;
			else b[i][j]=1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			c[i][j]=a[i][j];
		}
	}
	fun1();
	if(check1()){
		cout<<"1"<<endl;
		goto end;
	};
	fun1();
	if(check1()){
		cout<<"2"<<endl;
		goto end;
	};
	fun1();
	if(check1()){
		cout<<"3"<<endl;
		goto end;
	};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			c[i][n-j-1]=a[i][j];
		}
	}
	if(check1()){
		cout<<"4"<<endl;
		goto end;
	};
	fun1();
	if(check1()){
		cout<<"5"<<endl;
		goto end;
	};
	fun1();
	if(check1()){
		cout<<"5"<<endl;
		goto end;
	};
	fun1();
	if(check1()){
		cout<<"5"<<endl;
		goto end;
	};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			c[i][j]=a[i][j];
		}
	}
	if(check1()){
		cout<<"6"<<endl;
		goto end;
	};

	cout<<"7"<<endl;


end: 	return 0;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值