/home/toolbox/public_html/solutions/4/445/c.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 #define MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2015-03-10
20 * Purpose:
21 * Problem: 445
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 char chr;
29 int cnt;
30 char prev;
31
32 void init()
33 {
34 /* FUNCTION init */
35 cnt = 0;
36 chr = ' ';
37 } /* FUNCTION init */
38
39 void dump()
40 {
41 /* FUNCTION dump */
42 } /* FUNCTION dump */
43
44 int getInput()
45 {
46 /* FUNCTION getInput */
47 int dataReadFlag;
48
49 prev = chr;
50 chr = fgetc(stdin);
51 DEBUG printf("input: %d %d\n", prev, chr);
52 dataReadFlag = -1 != chr;
53 return (dataReadFlag);
54 } /* FUNCTION getInput */
55
56 void disp(char x, int c)
57 {
58 /* FUNCTION disp */
59 int i;
60
61 if ('b' == x)
62 {
63 x = ' ';
64 }
65 for (i=0; i<c; i++)
66 {
67 /* for */
68 printf("%c", x);
69 } /* for */
70 } /* FUNCTION disp */
71
72 void process()
73 {
74 /* FUNCTION process */
75 switch (chr)
76 {
77 /* switch */
78 case '!':
79 printf("\n");
80 cnt = 0;
81 break;
82 case '\n' :
83 if ('!' != prev)
84 {
85 printf("\n");
86 }
87 break;
88 case '0':
89 case '1':
90 case '2':
91 case '3':
92 case '4':
93 case '5':
94 case '6':
95 case '7':
96 case '8':
97 case '9':
98 cnt = cnt + chr - '0';
99 break;
100 default:
101 disp(chr, cnt);
102 cnt = 0;
103 break;
104 } /* switch */
105 prev = chr;
106 } /* FUNCTION process */
107
108 int main()
109 {
110 /* main */
111 int moreToDo;
112
113 init();
114 moreToDo = getInput();
115 while (moreToDo)
116 {
117 /* while */
118 process();
119 moreToDo = getInput();
120 } /* while */
121 DEBUG printf("\n");
122
123 return EXIT_SUCCESS;
124 } /* main */
125