/home/toolbox/public_html/solutions/109/10924/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 * Author: Isaac Traxler
17 * Date: 2015-03-15
18 * Purpose:
19 * Problem: 10924
20 */
21
22 /*
23 * This template reads lines of data at a time until end of file.
24 */
25
26 #define MAX_LINE 257
27 #define MAX_SIZE 2050
28
29 int num;
30 int buff[MAX_SIZE];
31 char line[MAX_LINE];
32
33
34 int init()
35 {
36 /* FUNCTION init */
37 int i;
38 int j;
39
40 buff[0] = 0;
41 buff[1] = 1;
42 buff[2] = 2;
43
44 /* sieve of erasthones */
45 for (i=3; i<MAX_SIZE; i=i+2)
46 {
47 buff[i]=i;
48 buff[i+1]=0;
49 }
50 for (i=3; i<MAX_SIZE; i=i+2)
51 {
52 /* loop through primes */
53 if (0 != buff[i])
54 {
55 /* found a prime */
56 for (j=i+i+i; j<MAX_SIZE; j=j+i+i)
57 {
58 /* mark out multiples */
59 buff[j] = 0;
60 } /* mark out multiples */
61 } /* found a prime */
62 } /* loop through primes */
63 } /* FUNCTION init */
64
65 void dump()
66 {
67 /* FUNCTION dump */
68 } /* FUNCTION dump */
69
70 int getInput()
71 {
72 /* FUNCTION getInput */
73 int dataReadFlag;
74
75 fgets(line, MAX_LINE, stdin);
76 if (feof(stdin))
77 dataReadFlag = FALSE;
78 else
79 {
80 /* something to read */
81 dataReadFlag = TRUE;
82 /*
83 line[strlen(line)-1] = 0;
84 */
85 } /* something to read */
86 return (dataReadFlag);
87 } /* FUNCTION getInput */
88
89 void process()
90 {
91 /* FUNCTION process */
92 int i;
93 int tot;
94
95 tot = 0;
96 for (i=0; i<strlen(line); i++)
97 {
98 /* for */
99 if (islower(line[i]))
100 {
101 tot = tot + line[i] - 'a' + 1;
102 }
103 if (isupper(line[i]))
104 {
105 tot = tot + line[i] - 'A' + 27;
106 }
107 } /* for */
108 printf("It is ");
109 if (0 == buff[tot])
110 {
111 /* not prime */
112 printf("not ");
113 } /* not prime */
114 printf("a prime word.\n");
115 } /* FUNCTION process */
116
117 int main()
118 {
119 /* main */
120 int moreToDo;
121
122 init();
123 moreToDo = getInput();
124 while (moreToDo)
125 {
126 /* while */
127 process();
128 moreToDo = getInput();
129 } /* while */
130
131 return EXIT_SUCCESS;
132 } /* main */
133