北航复试题是此题的简化,如果不是文件操作这题早就过了
/*
ID:linyvxi1
LANG:C++
TASK:transform
*/
//#include <stdio.h>
//#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int N;
char mat1[11][11],mat2[11][11];
char mat3[11][11];
bool degree_90()
{
int i,j;
for(i=1;i<=N;i++){
for(j=1;j<=N;j++)
if(mat1[i][j]!=mat2[j][N-i+1])
return false;
}
return true;
}
bool degree_180()
{
int i,j;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(mat1[i][j]!=mat2[N-i+1][N-j+1])
return false;
return true;
}
bool degree_270()
{
int i,j;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(mat1[i][j]!=mat2[N-j+1][i])
return false;
return true;
}
bool same()
{
int i,j;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
if(mat1[i][j]!=mat2[i][j])
return false;
return true;
}
bool refle()
{
int i,j;
if(N%2==0){
for(i=1;i<=N;i++)
for(j=1;j<=N/2;j++)
if(mat1[i][j]!=mat2[i][N-j+1])
return false;
return true;
}
else{
for(i=1;i<=N;i++)
if(mat1[i][N/2+1]!=mat2[i][N/2+1])
return false;
for(i=1;i<=N;i++)
for(j=1;j<=N/2;j++)
if(mat1[i][j]!=mat2[i][N-j+1])
return false;
return true;
}
return false;
}
bool f()
{
int i,j;
for(i=1;i<=N;i++){
for(j=1;j<=N;j++)
mat3[i][j]=mat1[i][N-j+1];
}
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
mat1[i][j]=mat3[i][j];
}
int main()
{
// FILE* fin=fopen("transform.in","r");
// FILE* fout=fopen("transform.out","w");
ifstream fin("transform.in");
int meth=7;
// fscanf(fin,"%d",&N);
fin>>N;
// scanf("%d",&N);
int i,j;
char temp;
// getchar();
for(i=1;i<=N;i++){
//fscanf(fin,"%c",&temp);
for(j=1;j<=N;j++)
// fscanf(fin,"%c",&mat1[i][j]);
fin>>mat1[i][j];
// scanf("%c",&mat1[i][j]);
}
for(i=1;i<=N;i++){
// fscanf(fin,"%c",&temp);
for(j=1;j<=N;j++)
// fscanf(fin,"%c",&mat2[i][j]);
fin>>mat2[i][j];
//scanf("%c",&mat2[i][j]);
}
if(degree_90())
meth=1;
else if(degree_180())
meth=2;
else if(degree_270())
meth=3;
else if(refle())
meth=4;
else if(same())
meth=6;
else{
f();
if(degree_90()||degree_180()||degree_270())
meth=5;
}
ofstream fout("transform.out");
fout<<meth<<endl;
fout.close();
}
依然给出测试数据
Here are the test data inputs:
------- test 1 ---- 3 --- --- --- --- -@- --- ------- test 2 ---- 5 -@@@- -@@-- -@--- ----- ----- ----- ----@ ---@@ --@@@ ----- ------- test 3 ---- 5 @@@@@ @---@ @@@@@ @@@@@ @@@@@ @@@@@ @@@@@ @@@@@ @---@ @@@@@ ------- test 4 ---- 6 -@-@-@ @-@-@- -@-@-@ @-@-@- -@-@-@ @-@-@- @-@-@- -@-@-@ @-@-@- -@-@-@ @-@-@- -@-@-@ ------- test 5 ---- 3 @@@ --- @@@ @@@ --- @@@ ------- test 6 ---- 4 @@@@ @@@@ -@@@ @@@@ @@@@ @@@@ @@@- @@@@ ------- test 7 ---- 4 @-@@ @@@@ @@@@ @@@@ @@@@ @@@@ @@@@ @-@@ ------- test 8 ---- 10 @--------@ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- @--------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------@