zoukankan      html  css  js  c++  java
  • 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;
    
    }
  • 相关阅读:
    raid阵列算法/数据恢复方法汇总
    EMC Isilon(OneFS)误删文件数据恢复过程<存储数据恢复>
    Raid磁盘阵列更换磁盘时另一块盘离线(v7000存储数据恢复)
    SqlServer数据库无法读取的数据恢复方案实施过程
    ds4800服务器lvm信息丢失数据恢复方案
    Hyper-V数据文件丢失数据恢复过程
    v7000存储数据恢复成功率分析-数据恢复初检报告
    Ext4文件系统fsck后损坏如何恢复?-北亚数据恢复
    服务器raid5两块硬盘离线lvm vxfs文件系统数据恢复过程
    临时表
  • 原文地址:https://www.cnblogs.com/superjn/p/5530615.html
Copyright © 2011-2022 走看看