USACO : transform(将输入字符串进行rotate,reflect)

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;


char a[100][100];
char b[100][100];
char t[100][100];
char d[100][100];

void rotate90(int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
           t[j][n-1- i] =  a[i][j];
        }
    }

}
void rotate180(int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            t[n - 1 - i][n - 1 - j] = a[i][j];
        }
    }

}
void rotate270(int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            t[n - 1 - j][i] = a[i][j];
        }
    }

}
void reflection(int n){
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            t[i][n - 1 - j] = a[i][j];
        }
    }

}
bool compare(char f[100][100],char c[100][100], int n){
    for(int i = 0; i < n; i++){
        for(int j = 0 ; j < n; j++){
            if(f[i][j] != c[i][j]){
                return false;
            }
        }
    }
    return true;
}
int main()
{
    ifstream fin;
    ofstream fout;
    fin.open("transform.in");
    fout.open("transform.out");
    int n;
    int result = 7;
    fin >> n;
    for(int i =0; i <n; i++){
        for(int j = 0; j< n; j++){
            fin >> a[i][j];
        }
    }
     for(int i =0; i <n; i++){
        for(int j = 0; j< n; j++){
            d[i][j] =  a[i][j];
        }
    }
    for(int i = 0; i <n; i++){
        for(int j = 0; j< n; j++){
            fin >> b[i][j];
        }
    }
    if(compare(b,a,n)){
        if(result > 6){
            result = 6;
        }
    }
    rotate90(n);
    if(compare(b,t,n)){
        if(result > 1){
            result = 1;
        }

    }
    rotate180(n);
    if(compare(b,t,n)){
        if(result > 2){
            result = 2;
        }
    }
    rotate270(n);
    if(compare(b,t,n)){
        if(result > 3){
            result = 3;
        }
    }
    reflection(n);
    if(compare(b,t,n)){
        if(result > 4){
            result = 4;
        }
    }

    reflection(n);
    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            a[i][j] = t[i][j];
        }
     }
     rotate90(n);
     if(compare(b,t,n)){
        if(result > 5){
            result = 5;
        }
    }
     for(int i =0; i <n; i++){
        for(int j = 0; j< n; j++){
            a[i][j] =  d[i][j];
        }
    }

    reflection(n);
    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            a[i][j] = t[i][j];
        }
     }
     rotate180(n);
     if(compare(b,t,n)){
        if(result > 5){
            result = 5;
        }
    }
    for(int i =0; i <n; i++){
        for(int j = 0; j< n; j++){
            a[i][j] =  d[i][j];
        }
    }

    reflection(n);
    for(int i = 0; i< n; i++){
        for(int j = 0; j < n; j++){
            a[i][j] = t[i][j];
        }
     }
     rotate270(n);
     if(compare(b,t,n)){
        if(result > 5){
            result = 5;
        }
    }
    for(int i =0; i <n; i++){
        for(int j = 0; j< n; j++){
            a[i][j] =  d[i][j];
        }
    }

    fout <<result<<endl;

}
原文地址:https://www.cnblogs.com/superjn/p/5530615.html