about summary refs log tree commit diff
path: root/others/easy20160714/29.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-02 20:37:59 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-02 20:37:59 +0700
commit57d767cf4e4d5b83645bda2c4e398fdd76d059e1 (patch)
tree557cc70d5dc663b5ee3bef2be4d749ddc3cfbc4c /others/easy20160714/29.c
parent7206ecee7579a10dd347d06b397b3790e969f8f3 (diff)
downloadcp-57d767cf4e4d5b83645bda2c4e398fdd76d059e1.tar.gz
Update others/easy20160714
Diffstat (limited to 'others/easy20160714/29.c')
-rw-r--r--others/easy20160714/29.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/others/easy20160714/29.c b/others/easy20160714/29.c
new file mode 100644
index 0000000..4e81aff
--- /dev/null
+++ b/others/easy20160714/29.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+
+char divpp(char x, char y)
+{
+	return (x % y) ? (x / y + 1) : (x / y);
+}
+
+float average(int a[10][10], char t, char l, char b, char r)
+{
+	float s = 0.0;
+	char i, j;
+
+	for (i = t; i <= b; i++)
+		for (j = l; j <= r; j++)
+			s += (float) a[i][j];
+
+	return s / (float) (b - t + 1) / (float) (r - l + 1);
+}
+
+int main()
+{
+	FILE *f = fopen("INP.TXT", "r");
+	char m, n, s, i, i0, j, j0, b = 1;
+	int a[10][10];
+	float r = 0;
+
+	fscanf(f, "%hhd %hhd %d", &m, &n, &s);
+
+	for (i = 0; i < m; i++)
+		for (j = 0; j < n; j++)
+			fscanf(f, "%d", &a[i][j]);
+
+	fclose(f);
+
+	for (i = 0; i < m; i++)
+		for (j = 0; j < n; j++)
+			for (i0 = i; i0 < m; i0++)
+				for (j0 = j + divpp(s, i0 - i + 1) - 1; j0 < n;
+				     j0++)
+					if (b || average(a, i, j, i0, j0) > r) {
+						r = average(a, i, j, i0, j0);
+						b = 0;
+					}
+
+	f = fopen("OUT.TXT", "w");
+	fprintf(f, "%f\n", r);
+	fclose(f);
+
+	return 0;
+}