71分,第二个第七个没过,求助
查看原帖
71分,第二个第七个没过,求助
1433409
nankong2005楼主2025/1/18 11:38
#include <bits/stdc++.h>
using namespace std;

const int MaxN = 11;
char fin[MaxN][MaxN];
int n;

void print(char a[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        puts(a[i] + 1);
}

bool pd(char a[][MaxN], char b[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (a[i][j] != b[i][j])
                return false;
    return true;
}

void rotate90(char mp[][MaxN], char a[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            a[j][n - i + 1] = mp[i][j];
}

void rotate180(char mp[][MaxN], char a[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            a[n - i + 1][n - j + 1] = mp[i][j];
}

void rotate270(char mp[][MaxN], char a[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            a[n - j + 1][i] = mp[i][j];
}

void reflect(char mp[][MaxN], char a[][MaxN]) {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            a[i][n - j + 1] = mp[i][j];
}

int transform(char mp[][MaxN]) {
    char a[MaxN][MaxN];
    
    rotate90(mp, a);
    if (pd(a, fin)) return 1;

    rotate180(mp, a);
    if (pd(a, fin)) return 2;

    rotate270(mp, a);
    if (pd(a, fin)) return 3;

    reflect(mp, a);
    if (pd(a, fin)) return 4;

    rotate90(a, a);
    if (pd(a, fin)) return 5;

    rotate180(a, a);
    if (pd(a, fin)) return 5;

    rotate270(a, a);
    if (pd(a, fin)) return 5;

    if (pd(mp, fin)) return 6;

    return 7;
}

int main() {
    char mp[MaxN][MaxN];
    scanf("%d", &n);

    for (int i = 1; i <= n; ++i)
        scanf("%s", mp[i] + 1);

    for (int i = 1; i <= n; ++i)
        scanf("%s", fin[i] + 1);

    printf("%d\n", transform(mp));
    
    return 0;
}
2025/1/18 11:38
加载中...