Skip to content

Instantly share code, notes, and snippets.

@cjxgm
Created July 9, 2014 14:37
Show Gist options
  • Save cjxgm/88001f4b7054c008ce96 to your computer and use it in GitHub Desktop.
Save cjxgm/88001f4b7054c008ce96 to your computer and use it in GitHub Desktop.
an elegant solution to poj 1102
#include <stdio.h>
static void hstretch(const char tbl[3], int n)
{
putchar(tbl[0]);
while (n--) putchar(tbl[1]);
putchar(tbl[2]);
putchar(' ');
}
static void shstretch(const char* str, const char* tbl, int n)
{
while (*str) hstretch(&tbl[(*str++ - '0') * 3], n);
putchar('\n');
}
static void svstretch(const char* str, const char* tbl, int n)
{
for (int i=0; i<n; i++) shstretch(str, tbl, n);
}
static void sstretch(const char* str, const char* tbls[5], int n)
{
shstretch(str, tbls[0], n);
svstretch(str, tbls[1], n);
shstretch(str, tbls[2], n);
svstretch(str, tbls[3], n);
shstretch(str, tbls[4], n);
putchar('\n');
}
static void render_digits(const char* str, int n)
{
static const char* tbls[] = {
" - - - - - - - - ",
"| | | | || || | || || |",
" - - - - - - - ",
"| | || | | || | || | |",
" - - - - - - - ",
};
sstretch(str, tbls, n);
}
int main()
{
int n;
char num[12];
while (scanf("%d%s", &n, num) != EOF && n)
render_digits(num, n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment