about summary refs log tree commit diff
path: root/others/easy20160714/08.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-01 21:05:53 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-01 21:15:44 +0700
commit7206ecee7579a10dd347d06b397b3790e969f8f3 (patch)
tree0b7218b75d8dae913fd91c695e105fc6f2256479 /others/easy20160714/08.c
parentc67182c04491f2cf8b67e78b68aebf32aea25470 (diff)
downloadcp-7206ecee7579a10dd347d06b397b3790e969f8f3.tar.gz
Add others/easy20160714
Diffstat (limited to 'others/easy20160714/08.c')
-rw-r--r--others/easy20160714/08.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/others/easy20160714/08.c b/others/easy20160714/08.c
new file mode 100644
index 0000000..c39fee9
--- /dev/null
+++ b/others/easy20160714/08.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#define sqr(x) x * x
+
+int cmp(const void *x, const void *y)
+{
+	return *(unsigned long *) x - *(unsigned long *) y;
+}
+
+int main()
+{
+	FILE *f = fopen("INP.TXT", "r");
+	char n, i, j, s[5] = {78, 79, 10};
+	unsigned long *a, c;
+	unsigned long long b;
+
+	fscanf(f, "%hhd", &n);
+	a = malloc(n * sizeof(unsigned long));
+
+	for (i = 0; i < n; i++)
+		fscanf(f, "%ld", a + i);
+
+	fclose(f);
+
+	qsort(a, n, sizeof(unsigned long), &cmp);
+
+	for (i = 0; i + 1 < n; i++)
+		for (j = i + 1; j < n; j++) {
+			b = sqr(a[i]) + sqr(a[j]);
+
+			c = (unsigned long) sqrt(b);
+
+			if (sqr(c) == b && bsearch(&c, a, n, 4, &cmp) != NULL) {
+				s[0] = 89;
+				s[1] = 69;
+				s[2] = 83;
+				s[3] = 10;
+
+				break;
+			}
+		}
+
+	f = fopen("OUT.TXT", "w");
+
+	fputs(s, f);
+
+	fclose(f);
+
+	return 0;
+}