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