Cod sursa(job #649322)

Utilizator yippeeErja Eduard yippee Data 15 decembrie 2011 19:00:56
Problema Potrivirea sirurilor Scor 4
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <string.h>
#include <stdio.h>

using namespace std;

int main()
{
    char s[100],s1[100],t[100];
    int poz[100];

    FILE *f = fopen("strmatch.in","r");
    FILE *g = fopen("strmatch.out","w");
    fscanf(f,"%s", s1);
    fscanf(f,"%s", s);

    int n = strlen(s), i = 0,m = strlen(s1), nr = 0;

    while(i<n)
    {
        char s2[100];
        strcpy(s2,"");
        while(strstr(s1,strncpy(t,s+i,1)) && i<n)
            {
                strcat(s2,t);
                if(strcmp(s1,s2) == 0)
                {
                   poz[nr] = i - m + 1;
                   nr++ ;
                   strcpy(s2,"");
                   i--;
                }
                i++;
            }
       i++;
    }

    fprintf(g,"%d\n", nr);
    for(int i=0; i<nr; i++)
      fprintf(g,"%d ", poz[i]);

    return 0;
}