/home/toolbox/public_html/solutions/132/13287/d.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-23
20 * Purpose: fun
21 * Problem: 13287
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 int moreToDo;
29 int width;
30 int lgth;
31 int tot;
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 getnum()
44 {
45 /* FUNCTION getNum */
46 int num = 0;
47 char x;
48
49 x = getchar();
50 while (isspace(x))
51 {
52 x = getchar();
53 }
54 while (isdigit(x))
55 {
56 /* while */
57 /*
58 num = (num * 10) + x - '0';
59 num * 10 == (num * 8) + (num * 2)
60 num << 3 == num * 8
61 num << 1 == num * 2
62 */
63 num = (num << 3) + (num << 1) + x - '0';
64 x = getchar();
65 } /* while */
66 return num;
67 } /* FUNCTION getNum */
68
69 int getInput()
70 {
71 /* FUANCTION getInput */
72 int i;
73 int x;
74 int y;
75 int cnt;
76 int moreToDo;
77
78 moreToDo = 0 < (scanf(" %d ", &width));
79 if (moreToDo)
80 {
81 /* read width -- so get rest of data */
82 tot = 0;
83 scanf(" %d ", &cnt);
84 DEBUG printf("(width = %d) (cnt = %d) (tot = %d)\n", width, cnt, tot);
85 for (i=0; cnt>i; i++)
86 {
87 /* for */
88 /*
89 scanf(" %d %d ", &x, &y);
90 */
91 x = getnum();
92 y = getnum();
93 tot = tot + (x * y);
94 } /* for */
95 DEBUG printf("(width = %d) (cnt = %d) (tot = %d)\n", width, cnt, tot);
96 } /* read width -- so get rest of data */
97 return moreToDo;
98 } /* FUNCTION getInput */
99
100 void process()
101 {
102 /* FUNCTION process */
103 lgth = tot / width;
104 printf("%d\n", lgth);
105 } /* FUNCTION process */
106
107 int main()
108 {
109 /* main */
110 int i;
111
112 moreToDo = getInput();
113 while (moreToDo)
114 {
115 /* while */
116 process();
117 moreToDo = getInput();
118 } /* while */
119
120 return EXIT_SUCCESS;
121 } /* main */
122
123