You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.2 KiB
C
70 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define ARR_LEN (1000)
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
FILE* fp = fopen("input.txt", "r");
|
|
if(!fp)
|
|
{
|
|
printf("FUCK");
|
|
return -1;
|
|
}
|
|
|
|
int bit_ct[12];
|
|
int diagnostic_arr[ARR_LEN];
|
|
|
|
|
|
memset(diagnostic_arr, 0, ARR_LEN * sizeof(int));
|
|
memset(bit_ct, 0, 12 * sizeof(int));
|
|
|
|
|
|
char* line = NULL;
|
|
size_t len = 0;
|
|
for(int ind = 0; ind < ARR_LEN; ind++)
|
|
{
|
|
ssize_t rc = getline(&line, &len, fp);
|
|
if(rc == -1)
|
|
{
|
|
break;
|
|
printf("FUCK\n");
|
|
return -1;
|
|
}
|
|
diagnostic_arr[ind] = strtol(line, NULL, 2);
|
|
for(int bit = 0; bit < 12; bit++)
|
|
{
|
|
bit_ct[bit] += ((diagnostic_arr[ind] & (1 << bit))>>bit);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/* uncomment this if u want to make ur code run like python */
|
|
/* int mat[1000][10000000]; */
|
|
|
|
/* for(int zind = 0; zind < 1000; zind++) */
|
|
/* { */
|
|
/* for(int zzind = 0; zzind < 10000000; zzind++) */
|
|
/* { */
|
|
/* mat[zzind][zind]= 0; */
|
|
/* } */
|
|
/* } */
|
|
int gamma = 0;
|
|
int dar = 0;
|
|
for(int bit = 0; bit < 12; bit++)
|
|
{
|
|
gamma += ((bit_ct[bit] > (ARR_LEN >> 1))<<bit);
|
|
dar += ((bit_ct[bit] < (ARR_LEN >> 1))<<bit);
|
|
printf("%d ", bit_ct[bit]);
|
|
}
|
|
printf("\n");
|
|
|
|
printf("solution %d\n", gamma*dar);
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
}
|