Posted on 2009-03-14 15:30
superman 阅读(117)
评论(0) 编辑 收藏 引用 所属分类:
USACO
1 #include <iostream>
2
3 using namespace std;
4
5 class Square
6 {
7 private:
8 char x[10][10];
9
10 public:
11 Square rotate();
12 Square reflect();
13 bool operator == (const Square &);
14 friend istream & operator >> (istream &, Square &);
15 friend ostream & operator << (ostream &, const Square &);
16 } ;
17
18 int n;
19 Square s, t;
20
21 int main()
22 {
23 freopen("transform.in", "r", stdin);
24 freopen("transform.out", "w", stdout);
25
26 cin >> n;
27 cin >> s >> t;
28
29 if (s.rotate() == t) { cout << 1 << endl; return 0; }
30 if (s.rotate().rotate() == t) { cout << 2 << endl; return 0; }
31 if (s.rotate().rotate().rotate() == t) { cout << 3 << endl; return 0; }
32 if (s.reflect() == t) { cout << 4 << endl; return 0; }
33 if (s.reflect().rotate() == t) { cout << 5 << endl; return 0; }
34 if (s.reflect().rotate().rotate() == t) { cout << 5 << endl; return 0; }
35 if (s.reflect().rotate().rotate().rotate() == t) { cout << 5 << endl; return 0; }
36 if (s == t) { cout << 6 << endl; return 0; }
37 cout << 7 << endl; return 0;
38 }
39
40 Square Square::rotate()
41 {
42 Square ns; //new square
43 for (int i = 0; i < n; i++)
44 for (int j = 0; j < n; j++)
45 ns.x[j][n - i - 1] = x[i][j];
46 return ns;
47 }
48
49 Square Square::reflect()
50 {
51 Square ns;
52 for (int i = 0; i < n; i++)
53 for (int j = 0; j < n; j++)
54 ns.x[i][n - j - 1] = x[i][j];
55 return ns;
56 }
57
58 bool Square::operator == (const Square & s)
59 {
60 for (int i = 0; i < n; i++)
61 for (int j = 0; j < n; j++)
62 if (x[i][j] != s.x[i][j])
63 return false;
64 return true;
65 }
66
67 istream & operator >> (istream & is, Square & s)
68 {
69 for (int i = 0; i < n; i++)
70 for (int j = 0; j < n; j++)
71 cin >> s.x[i][j];
72 return cin;
73 }
74
75 ostream & operator << (ostream & is, const Square & s)
76 {
77 for (int i = 0; i < n; i++)
78 {
79 for (int j = 0; j < n; j++)
80 cout << s.x[i][j];
81 cout << endl;
82 }
83 return cout;
84 }
85