- 1
- /*
- 2 ID:xiekeyi1
- 3 PROG:transform
- 4 LANG:C++
- 5 */
- 6#include 7 using namespace std;
- 8 //#define DEBUG
- 9 const int maxn = 15;
- 10 char a[maxn][maxn],
- b[maxn][maxn],
- c[maxn][maxn];
- 11 //template<typename T>
- 12 //void swap( T &a , T &b )
- 13 //{
- 14 // T c ;
- 15 // c = a ;
- 16 // a = b ;
- 17 // b = a ;
- 18 // return ;
- 19 //}
- 20 21 bool judge(char a[maxn][maxn], char b[maxn][maxn], int & n) 22 {
- 23
- for (int i = 1; i <= n; i++) 24
- for (int j = 1; j <= n; j++) 25
- if (a[i][j] != b[i][j]) 26
- return false;
- 27
- return true;
- 28
- }
- 29 30 31 int rolate(int & n) 32 {
- 33
- for (int i = 1; i <= n; i++) 34 {
- 35
- for (int j = 1; j <= n; j++) 36 {
- 37 c[j][n - i + 1] = a[i][j];
- 38
- }
- 39
- }
- 40
- if (judge(c, b, n)) 41
- return 1;
- 42 43
- for (int i = 1; i <= n; i++) 44 {
- 45
- for (int j = 1; j <= n; j++) 46 {
- 47 c[n - i + 1][n - j + 1] = a[i][j];
- 48
- }
- 49
- }
- 50
- if (judge(c, b, n)) 51
- return 2;
- 52 53
- for (int i = 1; i <= n; i++) 54 {
- 55
- for (int j = 1; j <= n; j++) 56 {
- 57 c[n - j + 1][i] = a[i][j];
- 58
- }
- 59
- }
- 60 61
- if (judge(c, b, n)) 62
- return 3;
- 63
- for (int i = 1; i <= n; i++) 64
- for (int j = 1; j <= n; j++) 65 c[i][j] = a[i][j];
- 66
- for (int i = 1; i <= n; i++) 67 {
- 68
- for (int j = 1; j <= n / 2; j++) 69 {
- 70 swap(c[i][j], c[i][n - j + 1]);
- 71
- }
- 72
- }
- 73
- if (judge(c, b, n)) 74
- return 4;
- 75 76 // for( int i = 1 ; i <= n ; i++)
- 77 // for( int j = 1 ; j <=n ; j++)
- 78 // c[i][j] = a[i][j] ;
- 79#ifdef DEBUG 80
- for (int i = 1; i <= n; i++) 81 {
- 82
- for (int j = 1; j <= n; j++) 83 cout << c[i][j];
- 84 cout << endl;
- 85
- }
- 86 cout << endl << endl;
- 87#endif 88 char d[maxn][maxn];
- 89
- for (int i = 1; i <= n; i++) 90
- for (int j = 1; j <= n; j++) 91 d[j][n - i + 1] = c[i][j];
- 92#ifdef DEBUG 93
- for (int i = 1; i <= n; i++) 94 {
- 95
- for (int j = 1; j <= n; j++) 96 cout << d[i][j];
- 97 cout << endl;
- 98
- }
- 99 cout << endl << endl;
- 100#endif 101
- if (judge(d, b, n)) 102
- return 5;
- 103
- for (int i = 1; i <= n; i++) 104
- for (int j = 1; j <= n; j++) 105 d[n - i + 1][n - j + 1] = c[i][j];
- 106#ifdef DEBUG 107
- for (int i = 1; i <= n; i++) 108 {
- 109
- for (int j = 1; j <= n; j++) 110 cout << d[i][j];
- 111 cout << endl;
- 112
- }
- 113 cout << endl << endl;
- 114#endif 115
- if (judge(d, b, n)) 116
- return 5;
- 117
- for (int i = 1; i <= n; i++) 118
- for (int j = 1; j <= n; j++) 119 d[n - j + 1][i] = a[i][j];
- 120#ifdef DEBUG 121
- for (int i = 1; i <= n; i++) 122 {
- 123
- for (int j = 1; j <= n; j++) 124 cout << d[i][j];
- 125 cout << endl;
- 126
- }
- 127 cout << endl << endl;
- 128#endif 129
- if (judge(d, b, n)) 130
- return 5;
- 131 132
- if (judge(a, b, n)) 133
- return 6;
- 134 135
- return 7;
- 136 137
- }
- 138 139 140 141 int main() 142 {
- 143 freopen("transform.in", "r", stdin);
- 144 freopen("transform.out", "w", stdout);
- 145 int n;
- 146 cin >> n;
- 147 char ch;
- 148
- for (int i = 1; i <= n; i++) 149
- for (int j = 1; j <= n; j++) 150 {
- 151 cin >> ch;
- 152 a[i][j] = ch;
- 153
- }
- 154 155
- for (int i = 1; i <= n; i++) 156
- for (int j = 1; j <= n; j++) 157 {
- 158 cin >> ch;
- 159 b[i][j] = ch;
- 160
- }
- 161 162 cout << rolate(n) << endl;
- 163
- return 0;
- 164
- }
来源: http://www.bubuko.com/infodetail-2030148.html