/home/toolbox/public_html/solutions/132/13215/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 <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2018-10-26
20 * Purpose: fun
21 * Problem: 13215
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 int numberOfTimes;
29 double sqrt3;
30 int lngth; /* length of park */
31 int wdth; /* width of park */
32 double sum; /* sum of the areas of each house */
33
34 void init()
35 {
36 /* FUNCTION init */
37 scanf("%d ", &numberOfTimes);
38 sqrt3 = sqrt(3);
39 } /* FUNCTION init */
40
41 int square(int side)
42 {
43 /* FUNCTION square */
44 return (side * side);
45 } /* FUNCTION square */
46
47 double triangle(int side)
48 {
49 /* FUNCTION triangle */
50 /* equilateral triangle
51 * area is sqrt(3) * side * side / 4
52 */
53 return ((sqrt3 * side * side)/4);
54 } /* FUNCTION triangle */
55
56 void dump()
57 {
58 /* FUNCTION dump */
59 } /* FUNCTION dump */
60
61 void getInput()
62 {
63 /* FUNCTION getInput */
64 int cnt;
65 int i;
66 char kind;
67 int tmp;
68 int flag = 1;
69
70 /* get number of houses */
71 scanf(" %d ", &cnt);
72 /* get first corner */
73 scanf("%c %d ", &kind, &tmp);
74 sum = square(tmp);
75 lngth = tmp;
76 /* loop or house 2 to cnt */
77 for (i=1; cnt>i; i++)
78 {
79 /* for each house */
80 scanf("%c %d ", &kind, &tmp);
81 if ('T' == kind)
82 {
83 /* triangle */
84 sum = sum + triangle(tmp);
85 } /* triangle */
86 else
87 {
88 /* square */
89 sum = sum + square(tmp);
90 } /* square */
91 if (1 == flag)
92 {
93 /* doing length */
94 lngth = lngth + tmp;
95 if ('C' == kind)
96 {
97 /* got to corner -- switch to width */
98 wdth = tmp;
99 flag++;
100 } /* got to corner -- switch to width */
101 } /* doing length */
102 else if (2 == flag)
103 {
104 /* doing width */
105 wdth = wdth + tmp;
106 if ('C' == kind)
107 {
108 flag++; /* end of width */
109 }
110 } /* doing width */
111 } /* for each house */
112 } /* FUNCTION getInput */
113
114 void process()
115 {
116 /* FUNCTION process */
117 int park;
118 double left;
119
120 park = lngth * wdth;
121 left = park - sum;
122 printf("%.4lf\n", left);
123 } /* FUNCTION process */
124
125 int main()
126 {
127 /* main */
128 int i;
129
130 init();
131 for (i=0; i<numberOfTimes; i++)
132 {
133 /* while */
134 getInput();
135 process();
136 } /* while */
137
138 return EXIT_SUCCESS;
139 } /* main */
140
141