Cod sursa(job #1210768)

Utilizator OwlreeRobert Badea Owlree Data 21 iulie 2014 00:26:40
Problema Potrivirea sirurilor Scor 80
Compilator c Status done
Runda Arhiva educationala Marime 0.65 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
  int n, t, i, j;
  char *a = (char *) malloc (2000005);
  char *b = (char *) malloc (2000005);
  char *c;
  int pos[2000000], cursor = 0;

  FILE *in = fopen("strmatch.in", "r");
  FILE *out = fopen("strmatch.out", "w");

  fscanf(in, "%s", a);
  fscanf(in, "%s", b);

  c = b;

  int count = 0;

  while(c = strstr(c, a)) {
    count++;
    pos[cursor++] = c - b;
    c += 1;
  }

  fprintf(out, "%d\n", count);

  int stop = count < 1000 ? count : 1000;
  for (i = 0; i < stop; ++i) {
    fprintf(out, "%d ", pos[i]);
  }

  fprintf(out, "\n");

  fclose(in);
  fclose(out);

  return 0;
}