summaryrefslogtreecommitdiff
path: root/euler99.c
diff options
context:
space:
mode:
Diffstat (limited to 'euler99.c')
-rw-r--r--euler99.c41
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);
+}