Pagini recente » Cod sursa (job #1277883) | Rating Ionel Herescu (zetta) | Cod sursa (job #1738759) | Cod sursa (job #2035940) | Cod sursa (job #2200340)
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#define MAX_LENGTH 2000000
int min(int first, int second) {
if (first < second)
return first;
return second;
}
int main() {
char *first, *second;
int numberOfPositionShow;
std::vector<unsigned long> positions;
int numberOfElements = 0;
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) {
unsigned long position = p - second;
positions.push_back(position);
numberOfElements++;
p = strstr(p + 1, first);
}
fprintf(output, "%d\n", numberOfElements);
for (int i = 0; i < min(1000, numberOfElements); i++) {
fprintf(output, "%llu ", positions[i]);
}
fclose(input);
fclose(output);
return 0;
}