/home/toolbox/public_html/solutions/6/621/b.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: 2020-05-18
20 * Purpose: fun
21 * Problem: 621 - Secret Research
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 int numberOfTimes;
29 int num;
30
31 void init()
32 {
33 /* FUNCTION init */
34 scanf("%d ", &numberOfTimes);
35 } /* FUNCTION init */
36
37 void dump()
38 {
39 /* FUNCTION dump */
40 } /* FUNCTION dump */
41
42 void getInput()
43 {
44 /* FUNCTION getInput */
45 scanf(" %d ", &num);
46 } /* FUNCTION getInput */
47
48 /***************
49 * + positive result S = 1 or S = 4 or S = 78
50 * - negative result S = S35
51 * * experiment failed S = 9S4
52 * ? experiment not completed S = 190S
53 */
54
55 char guess(int num)
56 {
57 /* FUNCTION guess */
58 char ret = '?';
59 int tmp;
60 int four = FALSE;
61
62 if (35 == (num % 100))
63 {
64 /* negative */
65 ret = '-';
66 } /* negative */
67 else
68 {
69 /* check for failed */
70 tmp = num;
71 while (9 < tmp)
72 {
73 /* keep reducing */
74 four = four || (tmp > 94) && (4 == (tmp % 10));
75 tmp = tmp / 10;
76 } /* keep reducing */
77 if (four && (9 == tmp))
78 {
79 /* FAILED */
80 ret = '*';
81 } /* FAILED */
82 } /* check for failed */
83 return ret;
84 } /* FUNCTION guess */
85
86 void process()
87 {
88 /* FUNCTION process */
89 char result;
90
91 switch (num)
92 {
93 /* switch */
94 case 1:
95 case 4:
96 case 78:
97 result = '+';
98 break;
99 case 135:
100 case 435:
101 case 7835:
102 result = '-';
103 break;
104 case 914:
105 case 944:
106 case 9784:
107 result = '*';
108 break;
109 case 1901:
110 case 1904:
111 case 19078:
112 result = '?';
113 break;
114 default:
115 result = guess(num);
116 } /* switch */
117 printf("%c\n", result);
118 } /* FUNCTION process */
119
120 int main()
121 {
122 /* main */
123 int i;
124
125 init();
126 for (i=0; i<numberOfTimes; i++)
127 {
128 /* while */
129 getInput();
130 process();
131 } /* while */
132
133 return EXIT_SUCCESS;
134 } /* main */
135
136