Pagini recente » Cod sursa (job #2361572) | Monitorul de evaluare | Cod sursa (job #2555856) | Cod sursa (job #2430846) | Cod sursa (job #2555145)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fin, *fout;
void find(char *tofind, char *s)
{
long int nr = 0, nrp = 0, positions[10000000];
char *p = strstr(s, tofind);
if(p == NULL)
{
fprintf(fout,"%ld",nr);
return;
}
nr++;
positions[nrp++] = p - s;
while((p = strstr(p+1, tofind)) != NULL)
{
nr++;
positions[nrp++] = p - s;
}
fprintf(fout,"%ld\n", nr);
for(int i = 0; i < nrp; i++)
{
fprintf(fout, "%ld ",positions[i]);
}
}
int main()
{
fin = fopen("strmatch.in","r"), fout = fopen("strmatch.out","w");
char s1[2000000], s2[2000000];
fgets(s1, 2000000, fin);
int l1 = strlen(s1);
fgets(s2, 2000000, fin);
s1[l1-1] = '\0';
find(s1,s2);
fclose(fin);fclose(fout);
return 0;
}