⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1966178_re.cpp

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CPP
字号:
# include <stdio.h>
# include <iostream.h>
# include <string.h>
# include <stdlib.h>

int sum;
char quilt[3001];
struct node
{
	char q[200][200];
	int height;
	int width;
}Q[100];
void output(struct node N);
void turn(struct node N)
{
	int i, j;
	struct node tmp;

	for(i = 0; i < N.height; i++)
		for(j = 0; j < N.width; j++)
		{
			tmp.q[j][N.height-i-1] = N.q[i][j];
			if(tmp.q[j][N.height-i-1]=='/')
				tmp.q[j][N.height-i-1] = '\\';
			else
				if(tmp.q[j][N.height-i-1]=='\\')
					tmp.q[j][N.height-i-1] = '/';
				else
					if(tmp.q[j][N.height-i-1]=='-')
						tmp.q[j][N.height-i-1] = '|';
					else
						if(tmp.q[j][N.height-i-1]=='|')
							tmp.q[j][N.height-i-1] = '-';
		}
	tmp.height = N.width;
	tmp.width = N.height;
	if(tmp.height>199||tmp.width>199||sum>99)
		while(1);
	Q[sum++] = tmp;
}

int sew(struct node M,struct node N)
{
	int i, j;
	struct node tmp;

	if(M.height!=N.height)
		return 0;
	tmp = M;
	for(i = 0; i < N.height; i++)
		for(j = 0; j < N.width; j++)
			tmp.q[i][j+M.width] = N.q[i][j];
	tmp.width += N.width;
	if(tmp.height>199||tmp.width>199||sum>99)
		while(1);
	Q[sum++] = tmp;
	return 1;
}

int work()
{
	int i;

	while(1)
	{
		if(strlen(quilt)==1)
			break;
		for(i = 0; quilt[i]!='\0'; i++)
		{
			if(quilt[i]==')')
			{
				if(quilt[i-2]=='(')
				{
					turn(Q[quilt[i-1]-'A']);
					quilt[i] = sum-1+'A';
					strcpy(&quilt[i-6],&quilt[i]);
				}
				else
				{
					if(sew(Q[quilt[i-3]-'A'],Q[quilt[i-1]-'A'])==0)
						return 0;
					quilt[i] = 'A'+sum-1;
					strcpy(&quilt[i-7],&quilt[i]);
				}
				break;
			}
		}
	}
	return 1;
}

void output(struct node N)
{
	int i, j;

	for(i = 0; i < N.height; i++)
	{
		for(j = 0; j < N.width; j++)
			printf("%c",N.q[i][j]);
		printf("\n");
	}
}

int main()
{
	int i, no;
	char ch;
	
	i = no = 0;
	Q[0].height = Q[1].height = Q[0].width = Q[1].width = 2;
	Q[0].q[0][0] = Q[0].q[0][1] = Q[0].q[1][0] = '/';
	Q[0].q[1][1] = '+';
	Q[1].q[0][0] = Q[1].q[0][1] = Q[1].q[1][0] = Q[1].q[1][1] = '-';
	while(cin>>ch)
	{
		if(ch!=' '&&ch!='\n')
		{
			if(ch==';')
			{
				printf("Quilt %d:\n",++no);
				quilt[i] = '\0';
				sum = 2;
				if(work()==0)
				{
					printf("error\n");
					i = 0;
					memset(quilt,'\0',sizeof(quilt));
					goto con;
				}
				else
					output(Q[quilt[0]-'A']);
				i = 0;
				memset(quilt,'\0',sizeof(quilt));
			}
			else
				quilt[i++]=ch;
		}
con : ;
	}
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -