/home/toolbox/public_html/solutions/4/445/b.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 DEBUG printf("[%c] %d\n", prev, prev);
84 if ('\n' == prev)
85 {
86 /* 2 newlines in a row -- blank line */
87 printf("\n\n");
88 } /* 2 newlines in a row -- blank line */
89 break;
90 case '0':
91 case '1':
92 case '2':
93 case '3':
94 case '4':
95 case '5':
96 case '6':
97 case '7':
98 case '8':
99 case '9':
100 cnt = cnt + chr - '0';
101 break;
102 default:
103 disp(chr, cnt);
104 cnt = 0;
105 break;
106 } /* switch */
107 prev = chr;
108 } /* FUNCTION process */
109
110 int main()
111 {
112 /* main */
113 int moreToDo;
114
115 init();
116 moreToDo = getInput();
117 while (moreToDo)
118 {
119 /* while */
120 process();
121 moreToDo = getInput();
122 } /* while */
123 DEBUG printf("\n");
124
125 return EXIT_SUCCESS;
126 } /* main */
127