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

📄 2042871_ac_62ms_1464k.cpp

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

using namespace std;

bool mark;
typedef struct node
{
	int h;
	int w;
	char q[100][100];
}Q;

Q A, B; 

void init()
{
	A.h = A.w = B.h = B.w = 2;
	strcpy(A.q[0],"//");strcpy(A.q[1],"/+");
	strcpy(B.q[0],"--");strcpy(B.q[1],"--");
}

bool is(char ch)
{
	if(ch==';'||ch=='('||ch==')'||ch==','||isalpha(ch))
		return 1;
	else
		return 0;
}

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

	if(M.h!=N.h)
	{
		mark = 1;
		return tmp;
	}
	tmp = M;
	for(i = 0; i < N.h; i++)
	{
		for(j = 0; j < N.w; j++)
			tmp.q[i][j+M.w] = N.q[i][j];
		tmp.q[i][j+M.w] = '\0';
	}
	tmp.w += N.w;
	return tmp;
}

Q turn(Q N)
{
	int i, j;
	Q tmp;

	for(i = 0; i < N.h; i++)
		for(j = 0; j < N.w; j++)
		{
			tmp.q[j][N.h-i-1] = N.q[i][j];
			if(tmp.q[j][N.h-i-1]=='/')
				tmp.q[j][N.h-i-1] = '\\';
			else
				if(tmp.q[j][N.h-i-1]=='\\')
					tmp.q[j][N.h-i-1] = '/';
				else
					if(tmp.q[j][N.h-i-1]=='-')
						tmp.q[j][N.h-i-1] = '|';
					else
						if(tmp.q[j][N.h-i-1]=='|')
							tmp.q[j][N.h-i-1] = '-';
			if(i==N.h-1)
				tmp.q[j][N.h] = '\0';
		}
	tmp.h = N.w;
	tmp.w = N.h;
	return tmp;
}

Q work(char q[])
{
	//puts(q);
	//system("pause");
	if(mark)
		return A;
	if(strcmp("A",q)==0)
		return A;
	if(strcmp("B",q)==0)
		return B;
	if(q[0]=='s')
	{
		int n = 0;
		char tmp1[5000], tmp2[5000];

		for(int i = 4; q[i] != '\0'; i++)
		{
			if(q[i]==','&&!n)
				break;
			if(q[i]=='(')
				n++;
			if(q[i]==')')
				n--;
		}
		strcpy(tmp1,&q[4]);
		tmp1[i-4] = '\0';
		strcpy(tmp2,&q[i+1]);
		tmp2[strlen(tmp2)-1] = '\0';
		return sew(work(tmp1),work(tmp2));
	}
	else
	{
		char tmp[5000];

		strcpy(tmp,&q[5]);
		tmp[strlen(tmp)-1] = '\0';
		return turn(work(tmp));
	}
}

void output(Q T)
{
	//printf("%d\n",T.h);
	for(int i = 0; i < T.h; i++)
		puts(T.q[i]);
}

void input()
{
	int l = 0, NO = 0;
	char ch;
	char quilt[5000];

	while(cin>>ch)
	{
		if(is(ch))
		{
			if(ch==';')
			{
				quilt[l] = '\0';
				printf("Quilt %d:\n",++NO);
				mark = 0;
				Q T;
				T = work(quilt);
				//ystem("pause");
				if(mark)
					printf("error\n");
				else
					output(T);
				
				l = 0;
				memset(quilt,'\0',sizeof(quilt));
			}
			else
				quilt[l++] = ch;
		}
	}
}

int main()
{
	init();
	input();
	return 1;
}

⌨️ 快捷键说明

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