/home/toolbox/public_html/solutions/109/10929/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-23
19 * Purpose:
20 * Problem: 10929
21 */
22
23 /*
24 * This template reads lines of data at a time until end of file.
25 */
26
27 #define MAX_LINE 1024
28
29 char line[MAX_LINE];
30
31 void init()
32 {
33 /* FUNCTION init */
34 } /* FUNCTION init */
35
36 void dump()
37 {
38 /* FUNCTION dump */
39 } /* FUNCTION dump */
40
41 int notZero()
42 {
43 /* FUNCTION notZero */
44 int i;
45 int zero = TRUE;
46
47 for (i=0; i<strlen(line); i++)
48 {
49 /* for */
50 if (isdigit(line[i]))
51 if ('0' != line[i])
52 {
53 /* non - zero digit found */
54 zero = FALSE;
55 i = MAX_LINE;
56 } /* non - zero digit found */
57 } /* for */
58 return (! zero);
59 } /* FUNCTION notZero */
60
61 int getInput()
62 {
63 /* FUNCTION getInput */
64 int dataReadFlag;
65
66 fgets(line, MAX_LINE, stdin);
67 line[strlen(line) - 1] = 0; /* strip newline */
68 dataReadFlag = notZero();
69 return dataReadFlag;
70 } /* FUNCTION getInput */
71
72 void process()
73 {
74 /* FUNCTION process */
75 int i;
76 int tot = 0;
77
78 for (i=0; i<strlen(line); i++)
79 {
80 /* for */
81 if (isdigit(line[i]))
82 {
83 /* just kind of ignore anything that is not a digit */
84 tot = tot * 10 + line[i] - '0';
85 tot = tot % 11;
86 } /* just kind of ignore anything that is not a digit */
87 } /* for */
88 printf("%s is ", line);
89 if (0 != tot)
90 {
91 printf("not ");
92 }
93 printf("a multiple of 11.\n");
94 } /* FUNCTION process */
95
96 int main()
97 {
98 /* main */
99 int moreToDo;
100
101 init();
102 moreToDo = getInput();
103 while (moreToDo)
104 {
105 /* while */
106 process();
107 moreToDo = getInput();
108 } /* while */
109
110 return EXIT_SUCCESS;
111 } /* main */
112