/home/toolbox/public_html/solutions/132/13215/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 <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 scanf(" %d ", &cnt);
71 scanf("%c %d ", &kind, &tmp);
72 sum = square(tmp);
73 lngth = tmp;
74 for (i=1; cnt>i; i++)
75 {
76 /* for each house */
77 scanf("%c %d ", &kind, &tmp);
78 if ('T' == kind)
79 {
80 /* triangle */
81 sum = sum + triangle(tmp);
82 } /* triangle */
83 else
84 {
85 /* square */
86 sum = sum + square(tmp);
87 } /* square */
88 if (1 == flag)
89 {
90 /* doing length */
91 lngth = lngth + tmp;
92 if ('C' == kind)
93 {
94 /* got to corner -- switch to width */
95 wdth = tmp;
96 flag++;
97 } /* got to corner -- switch to width */
98 } /* doing length */
99 else if (2 == flag)
100 {
101 /* doing width */
102 wdth = wdth + tmp;
103 if ('C' == kind)
104 {
105 flag++; /* end of width */
106 }
107 } /* doing width */
108 } /* for each house */
109 } /* FUNCTION getInput */
110
111 void process()
112 {
113 /* FUNCTION process */
114 int park;
115 double left;
116
117 park = lngth * wdth;
118 left = park - sum;
119 printf("%.4lf\n", left);
120 } /* FUNCTION process */
121
122 int main()
123 {
124 /* main */
125 int i;
126
127 init();
128 for (i=0; i<numberOfTimes; i++)
129 {
130 /* while */
131 getInput();
132 process();
133 } /* while */
134
135 return EXIT_SUCCESS;
136 } /* main */
137
138