summaryrefslogtreecommitdiff
path: root/3.c
diff options
context:
space:
mode:
Diffstat (limited to '3.c')
-rw-r--r--3.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/3.c b/3.c
new file mode 100644
index 0000000..39db01d
--- /dev/null
+++ b/3.c
@@ -0,0 +1,75 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static int FromBin(const char *p)
+{
+ int b = strlen(p) - 1;
+ int v = 0;
+ int f;
+
+ for(f = 0; p[f]; f++, b--)
+ {
+ if (p[f] == '1')
+ {
+ v |= 1 << b;
+ }
+ }
+
+ return v;
+}
+
+int main(void)
+{
+ char buff[80];
+ int bit[12] = {0};
+ int count = 0;
+ char str[13] = {0};
+ int f;
+ int gamma, epsilon;
+
+ while(fgets(buff, sizeof buff, stdin))
+ {
+ for(f = 0; f < 12; f++)
+ {
+ if (buff[f] == '1')
+ {
+ bit[f]++;
+ }
+ }
+
+ count++;
+ }
+
+ for(f = 0; f < 12; f++)
+ {
+ if (bit[f] > count / 2)
+ {
+ str[f] = '1';
+ }
+ else
+ {
+ str[f] = '0';
+ }
+ }
+
+ gamma = FromBin(str);
+
+ for(f = 0; f < 12; f++)
+ {
+ if (str[f] == '0')
+ {
+ str[f] = '1';
+ }
+ else
+ {
+ str[f] = '0';
+ }
+ }
+
+ epsilon = FromBin(str);
+
+ printf("%d\n", gamma * epsilon);
+
+ return 0;
+}