UVa Problem Solution: 706 - LC-Display

来源:互联网 发布:大众汽车ods软件 编辑:程序博客网 时间:2024/04/26 19:39

Output related problem. I use a predefined bitmap of all the numbers and enlarge them when displaying.

Code:

  1. /*************************************************************************
  2.  * Copyright (C) 2008 by liukaipeng                                      *
  3.  * liukaipeng at gmail dot com                                           *
  4.  *************************************************************************/
  5. /* @JUDGE_ID 00000 706 C "LC-Display" */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <strings.h>
  10. int bitmap_row(int r, int s)
  11. {
  12.   if (r == 0)
  13.     return 0;
  14.   else if (r == s+1)
  15.     return 2;
  16.   else if (r == 2*(s+1))
  17.     return 4;
  18.   else if (r < s+1)
  19.     return 1;
  20.   else
  21.     return 3;
  22. }
  23. int bitmap_col(int c, int s)
  24. {
  25.   if (c == 0)
  26.     return 0;
  27.   else if (c == s+1)
  28.     return 2;
  29.   else
  30.     return 1;
  31. }
  32. int main(int argc, char *argv[])
  33. {
  34. #ifndef ONLINE_JUDGE
  35.   char in[256];
  36.   char out[256];
  37.   strcpy(in, argv[0]);
  38.   strcat(in, ".in");
  39.   freopen(in, "r", stdin);
  40.   strcpy(out, argv[0]);
  41.   strcat(out, ".out");
  42.   freopen(out, "w", stdout);
  43. #endif
  44.   char bitmap[5][30] = { 
  45.     " -     -  -     -  -  -  -  - ",
  46.     "| |  |  |  || ||  |    || || |",
  47.     "       -  -  -  -  -     -  - ",
  48.     "| |  ||    |  |  || |  || |  |",
  49.     " -     -  -     -  -     -  - ",
  50.   };
  51.   int s, l, n, i, j, row, col;
  52.   char buf[10];
  53.   for (scanf("%d %s/n", &s, buf); s != 0; scanf("%d %s/n", &s, buf)) {
  54.     l = strlen(buf);
  55.     for (i = 0; i < 2*s+3; ++i) { 
  56.       row = bitmap_row(i, s);
  57.       for (j = 0; j < (s+2)*l; ++j) {
  58.         if (j > 0 && j % (s+2) == 0)
  59.           putchar(' ');
  60.         n = buf[j/(s+2)] - '0';
  61.         col = bitmap_col(j%(s+2), s);
  62.         col += 3*n;
  63.         putchar(bitmap[row][col]);
  64.       }
  65.       putchar('/n');
  66.     }
  67.     putchar('/n');
  68.   }
  69.   return 0;
  70. }