Pagini recente » Cod sursa (job #1700484) | Cod sursa (job #720588) | Cod sursa (job #2337052) | Cod sursa (job #2344864) | Cod sursa (job #2200345)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 2000000
int min(int first, int second) {
if (first < second)
return first;
return second;
}
int main() {
char *first, *second;
int numberOfElements = 0;
int index = 0;
unsigned long position;
FILE *input = fopen("strmatch.in", "r");
FILE *output = fopen("strmatch.out", "w");
first = (char *)malloc(MAX_LENGTH * sizeof(char));
second = (char *)malloc(MAX_LENGTH * sizeof(char));
fscanf(input, "%s", first);
fscanf(input, "%s", second);
char *p = strstr(second, first);
while (p != NULL) {
position = p - second;
if (index < 1000) {
fprintf(output, "%lu ", position);
index++;
}
numberOfElements++;
p = strstr(p + 1, first);
}
fprintf(output, "%d\n", numberOfElements);
fclose(input);
fclose(output);
return 0;
}