POJ 1102 LC-Display 题解(gcc) - 哆啦比猫's Blog - I'm an ArchLinuxer

POJ 1102 LC-Display 题解(gcc)

哆啦比猫 posted @ 2011年8月20日 11:36 in OI with tags OI POJ , 1744 阅读

http://poj.org/problem?id=1102


#include <stdio.h>

char isd(char ch)
{
	return ch >= 0 && ch < 10;
}

void print_lc(char size, char num[9]);

int main(void)
{
	int ch;
	char num[9];
	char size;

	while (1) {
		scanf("%hhd", &size);
		if (!size) break;

		while ((ch = getchar()) == ' ')  {}
		ungetc(ch, stdin);

		ch = 0;
		while (isd(num[ch++] = getchar() - '0')) {}
		num[--ch] = -1;

		print_lc(size, num);
	}

	return 0;
}

static char display[7][10] = {
	"- -- -----",	// upper
	"|   ||| ||",	// upper-left
	"|||||  |||",	// upper-right
	"  ----- --",	// mid
	"| |   | | ",	// bottom-left
	"|| |||||||",	// bottom-right
	"- -- -- --"	// bottom
};

static char line[90];

void print_lc(char size, char num[9])
{
	char s = size + 3;
	char i, j, k;

	line[s*i] = 0;

	// upper
	for (i=0; num[i] != -1; i++) {
		line[s*i] = ' ';
		line[s*i+size+1] = ' ';
		line[s*i+size+2] = ' ';
		for (j=1; j<=size; j++)
			line[s*i+j] = display[0][num[i]];
	}
	line[s*i-1] = 0;
	printf("%s\n", line);

	// upper-left/right
	for (i=0; num[i] != -1; i++) {
		line[s*i] = display[1][num[i]];
		line[s*i+size+1] = display[2][num[i]];
		line[s*i+size+2] = ' ';
		for (j=1; j<=size; j++)
			line[s*i+j] = ' ';
	}
	line[s*i-1] = 0;
	for (i=0; i<size; i++)
		printf("%s\n", line);
	
	// mid
	for (i=0; num[i] != -1; i++) {
		line[s*i] = ' ';
		line[s*i+size+1] = ' ';
		line[s*i+size+2] = ' ';
		for (j=1; j<=size; j++)
			line[s*i+j] = display[3][num[i]];
	}
	line[s*i-1] = 0;
	printf("%s\n", line);

	// bottom-left/right
	for (i=0; num[i] != -1; i++) {
		line[s*i] = display[4][num[i]];
		line[s*i+size+1] = display[5][num[i]];
		line[s*i+size+2] = ' ';
		for (j=1; j<=size; j++)
			line[s*i+j] = ' ';
	}
	line[s*i-1] = 0;
	for (i=0; i<size; i++)
		printf("%s\n", line);
	
	// bottom
	for (i=0; num[i] != -1; i++) {
		line[s*i] = ' ';
		line[s*i+size+1] = ' ';
		line[s*i+size+2] = ' ';
		for (j=1; j<=size; j++)
			line[s*i+j] = display[6][num[i]];
	}
	line[s*i-1] = 0;
	printf("%s\n\n", line);
}

凡未特殊声明(转载/翻译),所有文章均为原创。
by Giumo Xavier Clanjor (哆啦比猫/兰威举), 2010, 2011, 2012, 2013, 2014, 2015-2016 and 2017.
知识共享许可协议本作品采用知识共享署名·非商业性使用·相同方式共享 3.0 中国大陆许可协议进行许可。
文中凡未特殊声明且未声明为引用的代码均以 MIT 协议授权。

blog comments powered by Disqus
© 2010, 2011, 2012, 2013, 2014, 2015-2016 and 2017 Giumo Xavier Clanjor (哆啦比猫/兰威举).
© 2013, 2014, 2015-2016 and 2017 The Dark Colorscheme Designed by Giumo Xavier Clanjor (哆啦比猫/兰威举).
知识共享署名·非商业性使用·相同方式共享 3.0 中国大陆许可协议
| © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee