diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-05-24 21:39:58 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-05-24 21:39:58 +0800 |
commit | 1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db (patch) | |
tree | abde0e4da3c7fe138f3874a94d8eb7d0e44c3224 /euler99.c | |
download | project_euler-1eefd58ca4fdb5d2f51f657bfd70c9a89a4707db.tar.xz |
initial commit
Diffstat (limited to 'euler99.c')
-rw-r--r-- | euler99.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/euler99.c b/euler99.c new file mode 100644 index 0000000..e337796 --- /dev/null +++ b/euler99.c @@ -0,0 +1,41 @@ +#include <stdio.h> +#include <math.h> +#include <stdlib.h> +#include <string.h> + +struct elem +{ + int idx; + double v; +}; + +int comp(const void *s, const void *t) +{ + struct elem *ss = (struct elem*)s; + struct elem *tt = (struct elem*)t; + if (ss->v < tt->v) + return -1; + if (ss->v > tt->v) + return 1; + return 0; +} + +int main() +{ + struct elem arr[100000]; + int n; + char buffer[1000]; + + n = 0; + while (fgets(buffer, 1000, stdin)) { + if (strlen(buffer) < 3) + break; + int a = atoi(buffer); + int b = atoi(strchr(buffer, ',')+1); + arr[n].idx = n + 1; + arr[n].v = b * log(a); + n ++; + } + qsort(arr, n, sizeof(arr[0]), comp); + printf("%d\n", arr[n-1].idx); +} |