USACO 1.2.2 Transformations

Transformations

A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

  • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
  • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
  • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
  • #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
  • #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
  • #6: No Change: The original pattern was not changed.
  • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

In the case that more than one transform could have been used, choose the one with the minimum number above.

PROGRAM NAME: transform

INPUT FORMAT

Line 1:A single integer, N
Line 2..N+1:N lines of N characters (each either `@' or `-'); this is the square before transformation
Line N+2..2*N+1:N lines of N characters (each either `@' or `-'); this is the square after transformation

SAMPLE INPUT (file transform.in)

3
@-@
---
@@-
@-@
@--
--@

OUTPUT FORMAT

A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.

SAMPLE OUTPUT (file transform.out)

1
简单的小模拟 , 不过我犯了两个错。
首先,不会用二维数组做函数参数。
补习一下

C++中二位数组作为函数参数

变量在作用域里面被声明的是什么类型,就当作什么类型来用。

(1)参数是二维数组,但是要指定第二维的维数。

int array[10][10];

函数声明:void fuc(int a[][10]);

函数调用:fuc(array);

——在函数fuc中,a是二维数组。使用a[i][j]形式来访问数组中元素。

(2)参数使用一维指针数组。

int *array[10];

for(i = 0; i < 10; i++)

    array[i] = new int[10];

函数声明:void fuc(int *a[10]);

函数调用:fuc(array);

——在函数fuc中,a是一维指针数组。使用*(a[i] + j)形式来访问数组中元素。

(3)参数使用指针的指针。

int **array;

array = new int *[10];

for(i = 0; i <10; i++)

    array[i] = new int[10];

函数声明:void fuc(int **a);

函数调用:fuc(array);

——在函数fuc中, a是指针的指针。使用*(int *)(a + i*d2 + j)形式来访问数组中元素。其中:

a[0]<=>array[0][0],

a[1]<=>array[0][1],

a[10]<=>array[1][0]

注:d2为二维数组的二维维数,即列数。并且a + i*d2 + j为地址,所以要把这个类型为指针的指针的地址强制转换为指针来使用。

源自http://www.cnblogs.com/growup/archive/2011/03/01/1971529.html
其次 , 忘记了scanf("%c")会读入换行符。
/*
ID: xinming2
PROG: transform
LANG: C++
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
using namespace std;
char a[15][15];
char b[15][15];
char c[15][15];
int n , i  , j;
int f1(char a[][15] , char b[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            if(a[i][j] != b[j][n - i + 1])return 0;
        }
    }
    return 1;
}
int f2(char a[][15] , char b[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            if(a[i][j] != b[n - i + 1][n - j + 1])return 0;
        }
    }
    return 1;
}
int f3(char a[][15] , char b[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            if(a[i][j] != b[n - j + 1][i])return 0;
        }
    }
    return 1;
}
int f4(char a[][15] , char b[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            if(a[i][j] != b[i][n - j + 1])return 0;
        }
    }
    return 1;
}
void f5(char a[][15] , char c[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            c[i][j] = a[i][n - j + 1];
        }
    }
}
int f6(char a[][15] , char b[][15])
{
    for(i = 1;  i <= n ; i++)
    {
        for(j = 1 ; j <= n ; j++)
        {
            if(a[i][j] != b[i][j])return 0;
        }
    }
    return 1;
}
int main()
{

    freopen("transform.in","r",stdin);
    freopen("transform.out","w" , stdout);

    while(scanf("%d",&n)!=EOF)
    {
        for(i = 1 ; i <= n ; i++)
        {
            for(j = 1 ; j <= n ; j++)
            {
                cin >> a[i][j];
            }
        }
        for(i = 1 ; i <= n ; i++)
        {
            for(j = 1 ; j <= n ; j++)
            {
                cin >> b[i][j];
            }
        }
        f5(a , c);


        if(f1(a , b))printf("1\n");
        else if(f2(a , b))printf("2\n");
        else if(f3(a , b))printf("3\n");
        else if(f4(a , b))printf("4\n");
        else if(f1(b , c)||f2(b , c)||f3(b , c))printf("5\n");
        else if(f6(a , b))printf("6\n");
        else printf("7\n");
    }
    return 0;
}
/*

*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值