社区讨论
44分,写的很丑陋
P1205[USACO1.2] 方块转换 Transformations参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @lo32hymz
- 此快照首次捕获于
- 2023/10/23 23:43 2 年前
- 此快照最后确认于
- 2023/10/23 23:43 2 年前
CPP
#include <iostream>
using namespace std;
class square {
private:
int n;
char a [15][15], b[15][15];
public:
void assign() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> b[i][j];
}
}
}
void rotate_90_degrees() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
char t = a[i][j];
a[i][j] = a[j][i];
a[j][i] = t;
}
char t[15][15];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
t[i][j] = a[i][n + 1 - j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = t[i][j];
}
}
}
}
void rotate_180_degrees () {
rotate_90_degrees();
rotate_90_degrees();
}
void rotate_270_degrees() {
rotate_180_degrees();
rotate_90_degrees();
}
void mirror() {
char t[15][15];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
t[i][j] = a[i][n + 1 - j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = t[i][j];
}
}
}
void combination1() {
mirror();
rotate_90_degrees();
}
void combination2() {
mirror();
rotate_180_degrees();
}
void combination3() {
mirror();
rotate_270_degrees();
}
void keep() {
}
int contrast() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] != b[i][j]) {
return 0;
}
}
}
return 1;
}
};
int main() {
square s;
s.assign();
square s1 = s;
s1.rotate_90_degrees();
if (s1.contrast()) {
cout << "1";
} else {
square s2 = s;
s2.rotate_180_degrees();
if (s2.contrast()) {
cout << "2";
} else {
square s3 = s;
s3.rotate_180_degrees();
if (s3.contrast()) {
cout << "3";
} else {
square s4 = s;
s4.mirror();
if (s4.contrast()) {
cout << "4";
} else {
square s5_1 = s;
s5_1.combination1();
if (s5_1.contrast()) {
cout << "5";
} else {
square s5_2 = s;
s5_2.combination2();
if (s5_2.contrast()) {
cout << "5";
} else {
square s5_3 = s;
s5_3.combination3();
if (s5_3.contrast()) {
cout << "5";
} else {
square s6 = s;
s6.keep();
if (s6.contrast()) {
cout << "6";
} else {
cout << "7";
}
}
}
}
}
}
}
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...