this problem is from 1102 -- LC-Display
maybe, you have better code...
this is my code:
Code:
/**********************************
* Name: LC-display
* Author: thlgood(www.yucoat.com)
* Problem: http://poj.org/problem?id=1102
**********************************
#include <stdio.h>
int Map[10] = { 013031, 001010, 012111, 011111, 001130,
011121, 013121, 001011, 013131, 011131};
void Show(int bit, int value, int count)
{
int temp;
if (bit % 2)
{
char i = value==0?' ':'-';
putchar(' ');
for (temp = 0; temp < count; temp++)
putchar(i);
putchar(' ');
}
else
{
char i[2];
i[0] = (value / 2) == 0? ' ' : '|';
i[1] = (value % 2) == 0? ' ' : '|';
putchar(i[0]);
for (temp = 0; temp < count; temp++)
putchar(' ');
putchar(i[1]);
}
}
int main()
{
int s, duan, temp, getv;
char n[9];
while (scanf("%d%s", &s, n) && s != 0)
{
for (duan = 1, getv = 1; duan <= 5; duan++, getv *= 8)
{
int times = ((duan % 2) == 0 ? s : 1);
for (; times != 0; times--, putchar('\n'))
{
for (temp = 0; n[temp] != '\0'; temp++)
{
Show(duan, (Map[(n[temp] - '0')]/ getv) % 8, s);
if (n[temp + 1] != '\0')
putchar(' ');
}
}
}
putchar('\n');
}
return 0;
}