洛谷P1205 [USACO1.2] 方块转换 Transformations(C语言)

洛谷P1205 [USACO1.2] 方块转换 Transformations(C语言)_第1张图片洛谷P1205 [USACO1.2] 方块转换 Transformations(C语言)_第2张图片

#include
#include
#include
int A(char a1[11][11], char a2[11][11], int n)
{/*三个元素,两个数组,一个题目变量
 函数内会重新申请变量,需要规定大小*/
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		if (a1[i][j] != a2[j][n - i - 1])return 0;
	/*只有一句语句时不用大括号
	 函数返回一个值即结束*/
	return 1;
}/*不能从1开始,后续输入整串字符串时,每一串开头为0*/
int B(char a1[11][11], char a2[11][11], int n)
{
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		if (a1[i][j] != a2[n - i - 1][n - j - 1])return 0; return 1;
}
int C(char a1[11][11], char a2[11][11], int n)
{
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		if (a1[i][j] != a2[n - j - 1][i])return 0; return 1;
}
int D(char a1[11][11], char a2[11][11], int n)
{
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		if (a1[i][j] != a2[i][n - j - 1])return 0; return 1;
}
int E(char a1[11][11], char a2[11][11], int n)
{
	char a3[11][11];
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)a3[i][j] = a1[i][n - j - 1];
	if (A(a3, a2, n) == 1)return 1;
	if (B(a3, a2, n) == 1)return 1;
	if (C(a3, a2, n) == 1)return 1;
	return 0;
}
int F(char a1[11][11], char a2[11][11], int n)
{
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)
		if (a1[i][j] != a2[i][j])return 0; return 1;
}
int main()
{
	char a1[11][11], a2[11][11]; int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)scanf("%s", a1[i]);
	for (int i = 0; i < n; i++)scanf("%s", a2[i]);
	/*字符串不会读取回车*/
	  //ifelse语句中只会按顺序执行其中符合条件的一句
	if (A(a1, a2, n) == 1)printf("1");
	else if (B(a1, a2, n) == 1)printf("2");
	else if (C(a1, a2, n) == 1)printf("3");
	else if (D(a1, a2, n) == 1)printf("4");
	else if (E(a1, a2, n) == 1)printf("5");
	else if (F(a1, a2, n) == 1)printf("6");
	else printf("7");
	return 0;
}

你可能感兴趣的:(算法,数据结构,c语言)