A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:
In the case that more than one transform could have been used, choose the one with the minimum number above.
Line 1: | A single integer, N |
Line 2..N+1: | N lines of N characters (each either `@' or `-'); this is the square before transformation |
Line N+2..2*N+1: | N lines of N characters (each either `@' or `-'); this is the square after transformation |
3 @-@ --- @@- @-@ @-- --@
1
简单的小模拟 , 不过我犯了两个错。
首先,不会用二维数组做函数参数。
补习一下
C++中二位数组作为函数参数
源自http://www.cnblogs.com/growup/archive/2011/03/01/1971529.html
变量在作用域里面被声明的是什么类型,就当作什么类型来用。
(1)参数是二维数组,但是要指定第二维的维数。
int array[10][10];
函数声明:void fuc(int a[][10]);
函数调用:fuc(array);
——在函数fuc中,a是二维数组。使用a[i][j]形式来访问数组中元素。
(2)参数使用一维指针数组。
int *array[10];
for(i = 0; i < 10; i++)
array[i] = new int[10];
函数声明:void fuc(int *a[10]);
函数调用:fuc(array);
——在函数fuc中,a是一维指针数组。使用*(a[i] + j)形式来访问数组中元素。
(3)参数使用指针的指针。
int **array;
array = new int *[10];
for(i = 0; i <10; i++)
array[i] = new int[10];
函数声明:void fuc(int **a);
函数调用:fuc(array);
——在函数fuc中, a是指针的指针。使用*(int *)(a + i*d2 + j)形式来访问数组中元素。其中:
a[0]<=>array[0][0],
a[1]<=>array[0][1],
…
a[10]<=>array[1][0]
注:d2为二维数组的二维维数,即列数。并且a + i*d2 + j为地址,所以要把这个类型为指针的指针的地址强制转换为指针来使用。
其次 , 忘记了scanf("%c")会读入换行符。
/* ID: xinming2 PROG: transform LANG: C++ */ #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <map> #include <string> using namespace std; char a[15][15]; char b[15][15]; char c[15][15]; int n , i , j; int f1(char a[][15] , char b[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(a[i][j] != b[j][n - i + 1])return 0; } } return 1; } int f2(char a[][15] , char b[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(a[i][j] != b[n - i + 1][n - j + 1])return 0; } } return 1; } int f3(char a[][15] , char b[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(a[i][j] != b[n - j + 1][i])return 0; } } return 1; } int f4(char a[][15] , char b[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(a[i][j] != b[i][n - j + 1])return 0; } } return 1; } void f5(char a[][15] , char c[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { c[i][j] = a[i][n - j + 1]; } } } int f6(char a[][15] , char b[][15]) { for(i = 1; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { if(a[i][j] != b[i][j])return 0; } } return 1; } int main() { freopen("transform.in","r",stdin); freopen("transform.out","w" , stdout); while(scanf("%d",&n)!=EOF) { for(i = 1 ; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { cin >> a[i][j]; } } for(i = 1 ; i <= n ; i++) { for(j = 1 ; j <= n ; j++) { cin >> b[i][j]; } } f5(a , c); if(f1(a , b))printf("1\n"); else if(f2(a , b))printf("2\n"); else if(f3(a , b))printf("3\n"); else if(f4(a , b))printf("4\n"); else if(f1(b , c)||f2(b , c)||f3(b , c))printf("5\n"); else if(f6(a , b))printf("6\n"); else printf("7\n"); } return 0; } /* */