Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- int main() {
- FILE *in, *out;
- if(!(in=fopen("data.txt","r"))){
- printf("can't open data.txt\n");
- return -1;
- }
- if(!(out=fopen("result.txt","w"))){
- printf("can't open result.txt\n");
- fclose(in);
- return -1;
- }
- int m, n;
- scanf("%d %d", &n, &m);
- char s[80];
- scanf("%s", s);
- int *column = calloc(m, sizeof(int));
- int *index = calloc(m, sizeof(int));
- int *above = calloc(m, sizeof(int));
- int ans = 0;
- char curr;
- for (int i = 0; i < n; ++i) {
- //для проверки по горизонтали
- char prev = ' ';
- int len_curr = 0;
- for (int j = 0; j < m; ++j) {
- curr = fgetc(in);
- /*
- if (curr == ' ') {
- above[i] = 0;
- prev = ' ';
- continue;
- }
- */
- if (column[j]) {
- //printf("%d ", j);
- //если мы уже начали идти по столбцу
- if (index[j] == strlen(s)) {
- ++ans;
- column[j] = 0;
- index[j] = 0;
- }
- if (curr == s[index[j]])
- ++index[j];
- else {
- column[j] = 0;
- }
- } else {
- //если не начинали идти по столбцу
- if (!above[j]) {
- if (curr == s[0]) {
- column[j] = index[j] = 1;
- }
- }
- }
- if (!len_curr) {
- if (len_curr == strlen(s)) {
- ++ans;
- len_curr = 0;
- }
- if (curr == s[len_curr])
- ++len_curr;
- else
- len_curr = 0;
- }
- prev = curr;
- above[j] = curr == ' ' ? 0 : 1;
- }
- }
- printf("%d\n", ans);
- free(column);
- free(index);
- free(above);
- fclose(in);
- fclose(out);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement