/home/toolbox/public_html/solutions/132/13287/h.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 #define ZERO '0'
15
16 /* fprintf(stderr, "functionName: message", varslist); */
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2018-10-23
21 * Purpose: fun
22 * Problem: 13287
23 */
24
25 /*
26 * This template reads data a specified number of times.
27 */
28
29 int moreToDo;
30 int width;
31 int lgth;
32 int tot;
33 int i;
34 int x;
35 int cnt;
36 int num;
37 char xx;
38 char MASK;
39
40 void getnum()
41 {
42 /* FUNCTION getNum */
43 xx = getchar_unlocked();
44 while ((' ' == xx) || ('\n' == xx))
45 {
46 xx = getchar_unlocked();
47 }
48 num = xx - '0';
49 xx = getchar_unlocked();
50 while (('0' <= xx) && ('9' >= xx))
51 {
52 /* while */
53 /*
54 num = (num * 10) + x - '0';
55 num * 10 == (num * 8) + (num * 2)
56 num << 3 == num * 8
57 num << 1 == num * 2
58 num = (num << 3) + (num << 1) + xx - '0';
59 */
60 num = (num << 3) + (num << 1) + (xx & MASK);
61 xx = getchar_unlocked();
62 } /* while */
63 } /* FUNCTION getNum */
64
65 void getInput()
66 {
67 /* FUNCTION getInput */
68
69 moreToDo = 0 < (scanf(" %d ", &width));
70 if (moreToDo)
71 {
72 /* read width -- so get rest of data */
73 tot = 0;
74 getnum();
75 cnt = num;
76 for (i=0; cnt>i; i++)
77 {
78 /* for */
79 getnum();
80 x = num;
81 getnum();
82 tot = tot + (x * num);
83 } /* for */
84 } /* read width -- so get rest of data */
85 } /* FUNCTION getInput */
86
87 int main()
88 {
89 /* main */
90
91 MASK = ! ZERO;
92 getInput();
93 while (moreToDo)
94 {
95 /* while */
96 printf("%d\n", tot / width);
97 getInput();
98 } /* while */
99
100 return EXIT_SUCCESS;
101 } /* main */
102
103