-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformations
More file actions
182 lines (129 loc) · 2.71 KB
/
Transformations
File metadata and controls
182 lines (129 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
ID: gorakhm1
PROG: transform
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <fstream>
#define MAX 12
#define endl "\n"
using namespace std;
int firstThreeTransformations(char mat[MAX][MAX]);
void rotate_90(char mat[MAX][MAX]);
void mirror();
bool checkSimilar(char mat[MAX][MAX]);
void print(char mat[MAX][MAX]);
void copier(char mat[MAX][MAX]);
char a[MAX][MAX];
char b[MAX][MAX];
char t[MAX][MAX];
char temp[MAX][MAX];
int n;
void rotate_90(char mat[MAX][MAX]){
int r, c, k;
for(c = 0; c <= n - 1; c++){
for(r = n - 1, k = 0; r >= 0; r--, k++){
b[c][k] = mat[r][c];
}
}
}
void mirror(){
int r, c, k;
for(r = 0; r <= n - 1; r++){
for(c = n - 1, k = 0; c >= 0; c--, k++){
b[r][k] = a[r][c];
}
}
}
void copier(char mat[MAX][MAX]){
int i, j;
for(i = 0; i < n; i++){
for(j = 0 ; j< n; j++)
temp[i][j] = mat[i][j];
}
}
bool checkSimilar(char mat[MAX][MAX]){
int i, j;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
if(t[i][j] != mat[i][j])
return false;
}
}
return true;
}
int firstThreeTransformations(char mat[MAX][MAX]){
rotate_90(mat);
// print(b);
copier(b);
if(checkSimilar(b))
return 1;
rotate_90(temp);
// print(b);
copier(b);
if(checkSimilar(b))
return 2;
rotate_90(temp);
//print(b);
copier(b);
if(checkSimilar(b))
return 3;
return 0;
}
void print(char mat[MAX][MAX]){
int i, j;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
printf("%c ", mat[i][j]);
}
printf("\n");
}
printf("\n");
}
int main() {
ifstream fin("transform.in");
ofstream fout("transform.out");
//scanf("%d", &n);
fin >> n;
int i, j, k;
for(i = 0; i < n; i++){
// scanf("%s", a[i]);
fin >> a[i];
}
for(i = 0; i < n; i++){
// scanf("%s", t[i]);
fin >> t[i];
}
/*k = firstThreeTransformations(a);
mirror();
print(b);
copier(b);
firstThreeTransformations(temp);*/
if(k = firstThreeTransformations(a)){
// printf("%d\n", k);
fout << k << endl;
}
else {
mirror();
copier(b);
if(checkSimilar(b)){
// printf("4\n");
fout << 4 << endl;
}
else {
if(firstThreeTransformations(temp)){
// printf("5\n");
fout << 5 << endl;
}
else{
if(checkSimilar(a))
// printf("6\n");
fout << 6 << endl;
else //printf("7\n");
fout << 7 << endl;
}
}
}
return 0;
}