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

📄 1794.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 1794 on 2006-09-14 at 16:07:16 */
#include <cstdio>
#include <algorithm>
using namespace std;
 
const int N = 128;
 
char map[N][N];
 
int sgn(int x) { return x == 0 ? 0 : x/abs(x); }
void printSep(int);
void drawChar(int, int, char);
void drawLine(int, int, int, int);
bool same(char, char);
 
int main()
{
	int w, h;
 
	while(scanf("%d %d", &w, &h) != EOF && w*h != 0) {
		memset(map, ' ', sizeof(map));
		char cmd[16], text[128];
		bool end = false;
		while(!end) {
			int x1, y1, x2, y2, l, r, u, d;
			scanf("%s", cmd);
			switch(cmd[1]) {
			case 'O':
				scanf("%d %d", &x1, &y1);
				drawChar(y1-1, x1-1, 'o');
			break;
			case 'E':
				scanf("%d %d %s", &x1, &y1, text);
				for(int i = 0; text[i] != 0 && x1+i <= w; i++) drawChar(y1-1, x1+i-1, text[i]);
			break;
			case 'I':
				scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
				drawLine(y1-1, x1-1, y2-1, x2-1);
			break;
			case 'L':
				scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
				l = min(x1, x2); r = max(x1, x2); d = min(y1, y2); u = max(y1, y2);
				for(int i = d-1; i < u; i++)
					for(int j = l-1; j < r; j++) map[i][j] = ' ';
			break;
			case 'R': end = true; break;
			}
		}
		printSep(w);
		for(int i = 0; i < h; i++) printf("|%.*s|\n", w, map[i]);
		printSep(w); printf("\n");
	}
	
	return 0;
}
 
void printSep(int w)
{
	putchar('+');
	for(int i = 0; i < w; i++) putchar('-');
	printf("+\n");
}
void drawChar(int x, int y, char c)
{
	if(map[x][y] == ' ') map[x][y] = c;
	else if(same(map[x][y], c)) return;
	else if(map[x][y]+c == '-'+'|') map[x][y] = '+';
	else if(map[x][y]+c == '/'+'\\') map[x][y] = 'x';
	else map[x][y] = '*';
}
void drawLine(int x1, int y1, int x2, int y2) {
	char lc;
	int dx = sgn(x2-x1), dy = sgn(y2-y1);
	if(dx == 0) lc = '-';
	else if(dy == 0) lc = '|';
	else if(dx*dy > 0) lc = '\\';
	else lc = '/';
	for(; x1 != x2 || y1 != y2; x1 += dx, y1 += dy) drawChar(x1, y1, lc);
	drawChar(x2, y2, lc);
}
bool same(char a, char b)
{
	if(a == '*' || b == '*' || a == b) return true;
	else if(a+b == '+'+'-' || a+b == '+'+'|') return true;
	else if(a+b == 'x'+'/' || a+b == 'x'+'\\') return true;
	else return false;
}

⌨️ 快捷键说明

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