/home/toolbox/public_html/solutions/109/10945/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: 2016-09-06
18 * Purpose: fun
19 * Problem: 10945 - Mother Bear
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 #define MAX 10000
27
28 char line[MAX];
29
30 void init()
31 {
32 /* FUNCTION init */
33 } /* FUNCTION init */
34
35 void dump()
36 {
37 /* FUNCTION dump */
38 } /* FUNCTION dump */
39
40 int getInput()
41 {
42 /* FUNCTION getInput */
43 int dataReadFlag;
44 int tmp;
45
46 fgets(line, MAX, stdin);
47 line[strlen(line)-1] = 0;
48 dataReadFlag = (0 != strcmp("DONE", line));
49 return (dataReadFlag);
50 } /* FUNCTION getInput */
51
52 void process()
53 {
54 /* FUNCTION process */
55 int i;
56 int j;
57 int pal = TRUE;
58 int tmp;
59
60 /* cleanse input */
61 tmp = strlen(line);
62 DEBUG printf("%d [%s]\n", tmp, line);
63 for (i=0, j=0; i<tmp; i++)
64 {
65 /* look at each charcter */
66 if (isalpha(line[i]))
67 {
68 /* keep character */
69 line[j] = tolower(line[i]);
70 j++;
71 } /* keep character */
72 } /* look at each charcter */
73 line[j] = 0;
74 DEBUG printf("%d [%s]\n", j, line);
75 tmp = j - 1; /* to make math work when subtracting below */
76 /* now check for palindrone */
77 for (i=0; (pal) && ((j/2)>i); i++)
78 {
79 /* for */
80 pal = (line[i] == line[tmp - i]);
81 } /* for */
82 if (pal)
83 printf("You won't be eaten!\n");
84 else
85 printf("Uh oh..\n");
86 } /* FUNCTION process */
87
88 int main()
89 {
90 /* main */
91 int moreToDo;
92
93 init();
94 moreToDo = getInput();
95 while (moreToDo)
96 {
97 /* while */
98 process();
99 moreToDo = getInput();
100 } /* while */
101
102 return EXIT_SUCCESS;
103 } /* main */
104