Pagini recente » Cod sursa (job #979611) | Cod sursa (job #1869328) | Cod sursa (job #1807405) | Cod sursa (job #2557960) | Cod sursa (job #2779786)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char a[2000001], b[2000001];
int cnt;
queue<int> my_Queue;
void cautare_subsir_in_subsir(char a[], char b[], int a_length){
char subsir[20000001];
strcpy(subsir, strstr(a,b));
int len = strlen(subsir);
if(len) {
cnt++;
my_Queue.push(a_length - len);
cautare_subsir_in_subsir(subsir, b, len);
}
}
int main(){
int l_max, b_sir_max;
fin.getline(a, 2000001);
fin.getline(b, 2000001);
if(strlen(a) > strlen(b))
l_max = strlen(a), b_sir_max = 0;
else l_max = strlen(b), b_sir_max = 1;
if(b_sir_max){
//cautare_subsir_in_subsir(b,a,l_max);
int last_length= 0;
while(strlen(b) > strlen(a)){
char subsir[2000001];
strcpy(subsir, strstr(b,a));
int len = strlen(subsir);
if(len){
cnt++;
last_length= last_length + strlen(b) - len;
my_Queue.push(last_length);
strcpy(b,subsir+1);
last_length++;
}
}
}else {
//cautare_subsir_in_subsir(a,b,l_max);
int last_length= 0;
while(strlen(a) > strlen(b)){
char subsir[2000001];
strcpy(subsir, strstr(a,b));
int len = strlen(subsir);
if(len){
cnt++;
last_length= last_length + strlen(a) - len;
my_Queue.push(last_length);
strcpy(a,subsir+1);
last_length++;
}
}
}
cout << cnt;
cout << endl;
while(!my_Queue.empty()){
cout << my_Queue.front() << ' ';
my_Queue.pop();
}
return 0;
}