diff options
Diffstat (limited to '6a.c')
-rw-r--r-- | 6a.c | 40 |
1 files changed, 14 insertions, 26 deletions
@@ -2,8 +2,6 @@ #include <stdio.h> #include <string.h> -#define MAX_BOARDS 100 - static char *ReadLine(char *p, size_t size, FILE *fp) { if ((p=fgets(p, size, fp))) @@ -22,10 +20,10 @@ static char *ReadLine(char *p, size_t size, FILE *fp) int main(void) { char buff[1024]; - char *num = NULL; + unsigned long long num[9] = {0}; unsigned long long num_count = 0; char *p = NULL; - unsigned long long f = 0; + int f = 0; int cycle = 0; ReadLine(buff, sizeof buff, stdin); @@ -34,38 +32,28 @@ int main(void) while(p) { - num = realloc(num, (num_count + 1) * sizeof *num); - num[num_count++] = atoi(p); + num[atoi(p)]++; p = strtok(NULL, ","); } for(cycle = 0; cycle < 256; cycle++) { - int to_add = 0; + unsigned long long zero = 0; - for(f = 0; f < num_count; f++) - { - if (num[f] == 0) - { - to_add++; - num[f] = 6; - } - else - { - num[f]--; - } - } + zero = num[0]; - if (to_add) + for(f=0; f < 8; f++) { - num = realloc(num, (num_count + to_add) * sizeof *num); - for(f = 0; f < to_add; f++) - { - num[num_count++] = 8; - } + num[f] = num[f+1]; } - printf("cycle/num_count = %d/%llu\n", cycle, num_count); + num[6] += zero; + num[8] = zero; + } + + for(f = 0; f < 9; f++) + { + num_count += num[f]; } printf("num_count=%llu\n", num_count); |