|
|
back to boardWA #17 why? Posted by Иван 17 Jun 2014 19:06 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define True 1 #define False 0 #define N 15 #define MAX_DIFF 1000000000000000001 void print_a(unsigned long long a[N]) { int i; printf("\n----------------\n"); for (i = 0; a[i] != 0; i++) { printf("%llu\n", a[i]); } printf("\n--------------\n"); } void sort(unsigned long long a[N]) { int i, j, s_fl; unsigned long long tmp; for (i = 0, s_fl = True; s_fl == True; i++) { for (j = 0, s_fl = False; j < N-i-1; j++) { if (a[j] < a[j + 1]) { s_fl = True; tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp; } } } } int main(int argc, char *argv[]) { int i, j, c; unsigned long long prev, diff; unsigned long long max[N] = {0}; for (i = 0; i < 3; i++) scanf("%llu", &max[i]); sort(max);
for (j = 2, c = 0; max[j] != 0; j++, c++) { for (i = 0, diff = MAX_DIFF; max[i + 1] != 0; i++) { prev = max[i] - max[i + 1]; if (prev < diff) diff = prev; } max[j + 1] = diff; sort(max); // print_a(max); } printf("%d\n", c); return 0; } |
|
|