diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-01-20 22:25:31 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2017-01-20 22:31:32 +0700 |
commit | 6750cd9d0a92f9f5ef544ea9f13ae3419769fb3b (patch) | |
tree | b3d2c74093c2b7be5f019179b9c295c97da5d9eb /others/153x/fibistr.c | |
parent | 1fca99158c60a94497b21ff527d4071d96c9c0f1 (diff) | |
download | cp-6750cd9d0a92f9f5ef544ea9f13ae3419769fb3b.tar.gz |
Add others/153x
Diffstat (limited to 'others/153x/fibistr.c')
-rw-r--r-- | others/153x/fibistr.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/others/153x/fibistr.c b/others/153x/fibistr.c new file mode 100644 index 0000000..e3e55d8 --- /dev/null +++ b/others/153x/fibistr.c @@ -0,0 +1,46 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +char streq(char *x, char *y) +{ + char i; + + for (i = 0; i < strlen(x); i++) + if (x[i] != y[i]) + return 0; + + return 1; +} + +int main() +{ + FILE *fi = fopen("FIBISTR.INP", "r"), *fo = fopen("FIBISTR.OUT", "w"); + char **fibi = malloc(35 * sizeof(char *)), s[26], n; + long i, c; + + fibi[0] = malloc(2); + fibi[1] = malloc(2); + fibi[0][0] = 65; + fibi[1][0] = 66; + fibi[0][1] = fibi[1][1] = 0; + + for (i = 2; i < 35; i++) { + fibi[i] = malloc(strlen(fibi[i - 1]) + strlen(fibi[i - 2]) + 1); + strcpy(fibi[i], fibi[i - 1]); + strcpy(fibi[i] + strlen(fibi[i - 1]), fibi[i - 2]); + } + + do { + fscanf(fi, "%hhd %s\n", &n, s); + n--; + c = 0; + for (i = strlen(fibi[n]) - strlen(s); i >= 0; i--) + c += streq(s, fibi[n] + i); + fprintf(fo, "%ld\n", c); + } while (!feof(fi)); + + fcloseall(); + return 0; +} |