about summary refs log tree commit diff
path: root/others/dict/dict.c
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-10 21:30:06 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-10 21:35:08 +0700
commit7c9b47ab9149d292d5493c865dfb8742a7450472 (patch)
treec2b8d9759740b02b9dc157b84f32c2860369bf3b /others/dict/dict.c
parentf4f486fb4b37b72ca345f95881e44043c728b2c3 (diff)
downloadcp-7c9b47ab9149d292d5493c865dfb8742a7450472.tar.gz
others/other: Add {bin,game}.pas and move others/dict here
Diffstat (limited to 'others/dict/dict.c')
-rw-r--r--others/dict/dict.c53
1 files changed, 0 insertions, 53 deletions
diff --git a/others/dict/dict.c b/others/dict/dict.c
deleted file mode 100644
index 9821828..0000000
--- a/others/dict/dict.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-int cmpstr(const void *s1, const void *s2)
-{
-	return strcmp((char *) s1, (char *) s2);
-}
-
-short bistr(char (*a)[21], char *x, short hi)
-{
-	short lo = 0, mid;
-
-	while (lo < hi) {
-		mid = (lo + hi) / 2;
-		if (strcmp(a[mid], x) < 0)
-			lo = mid + 1;
-		else
-			hi = mid;
-	}
-
-	return lo;
-}
-
-int main()
-{
-	FILE *fi = fopen("dict.inp", "r"), *fo = fopen("dict.out", "w");
-	short n, q, i, idx, count;
-	char (*words)[21], s[21];
-
-	fscanf(fi, "%hd", &n);
-
-	words = malloc(n * 21);
-	for (i = 0; i < n; i++)
-		fscanf(fi, "%s", words[i]);
-	qsort(words, n, 21, cmpstr);
-
-	fscanf(fi, "%hd", &q);
-
-	for (i = 0; i < q; i++) {
-		fscanf(fi, "%s", s);
-		idx = bistr(words, s, n);
-		count = idx;
-		while (count < n && !strncmp(words[count], s, strlen(s)))
-			count++;
-		fprintf(fo, "%hd\n", count - idx);
-	}
-
-	fclose(fi);
-	fclose(fo);
-
-	return 0;
-}