/home/toolbox/public_html/solutions/4/490/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
16 /*
17 * Author: Isaac Traxler
18 * Date: 2015-03-12
19 * Purpose:
20 * Problem: 490
21 */
22
23 /*
24 * This template reads lines of data at a time until end of file.
25 */
26
27 #define MAX_LINE 300
28 int lineCnt = 0;
29 int maxLength = 0;
30
31 char line[MAX_LINE][MAX_LINE];
32
33 void init()
34 {
35 /* FUNCTION init */
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 int getInput()
44 {
45 /* FUNCTION getInput */
46 int dataReadFlag;
47
48 fgets(line[lineCnt], MAX_LINE, stdin);
49 if (feof(stdin))
50 dataReadFlag = FALSE;
51 else
52 {
53 /* something to read */
54 dataReadFlag = TRUE;
55 line[lineCnt][strlen(line[lineCnt])-1] = 0;
56 DEBUG printf("%d: %d [%s]\n", lineCnt, strlen(line[lineCnt]), line[lineCnt]);
57 if (strlen(line[lineCnt]) > maxLength)
58 {
59 maxLength = strlen(line[lineCnt]);
60 }
61 DEBUG printf("%3d: [%s] %d\n", lineCnt, line[lineCnt], maxLength);
62 lineCnt++;
63 } /* something to read */
64 return (dataReadFlag);
65 } /* FUNCTION getInput */
66
67 void process()
68 {
69 /* FUNCTION process */
70 int i;
71 int j;
72
73 for (i=0; i<maxLength; i++)
74 {
75 /* for */
76 for (j=(lineCnt - 1); 0<= j; j--)
77 {
78 /* for */
79 if (strlen(line[j]) > i)
80 {
81 /* something to print */
82 DEBUG printf("process %3d: [%s] %d\n", j, line[j], i);
83 printf("%c", line[j][i]);
84 } /* something to print */
85 else
86 {
87 /* print a space */
88 printf(" ");
89 } /* print a space */
90 } /* for */
91 printf("\n");
92 } /* for */
93 } /* FUNCTION process */
94
95 int main()
96 {
97 /* main */
98 int moreToDo;
99
100 init();
101 moreToDo = getInput();
102 while (moreToDo)
103 {
104 /* while */
105 moreToDo = getInput();
106 } /* while */
107 process();
108
109 return EXIT_SUCCESS;
110 } /* main */
111