Pagini recente » Istoria paginii runda/nush_chare | Cod sursa (job #2058355) | Cod sursa (job #2725933) | Cod sursa (job #642642) | Cod sursa (job #244225)
Cod sursa(job #244225)
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int main() {
char *str, *substr, *buffer = new char[2000001];
FILE* io;
io = fopen("strmatch.txt", "r");
fgets(buffer, 2000000, io);
substr = new char[strlen(buffer)+1];
strcpy(substr, buffer);
fgets(buffer, 2000000, io);
str = new char[strlen(buffer)+1];
strcpy(str, buffer);
delete[] buffer;
fclose(io);
substr[strlen(substr)-1] = '\0';
vector<int> results;
char* x = str-1;
do{
x = strstr(x+1, substr);
results.push_back(x-str);
}while(x != NULL);
int y = results.size()-1;
io = fopen("strmatch2.txt", "w");
fprintf(io, "%d\n", y);
for(int i = 0; i < y && i < 1000; i++)
fprintf(io, "%d ", results[i]);
}