Pagini recente » Cod sursa (job #3267041) | Cod sursa (job #72402) | Cod sursa (job #1152473) | Cod sursa (job #624750) | Cod sursa (job #272804)
Cod sursa(job #272804)
#include<fstream.h>
#include<string.h>
char a[2000],b[2000],c;
int y[2000];
int main()
{
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
fin>>a;
//fin>>b;
int i=0,ok=0,p,x=0,l=0,f;
while (fin>>b[i] && b[i]!=NULL)
{
if (ok==0)
{
if (a[0]==b[i])
{
ok=1;
p=1;
f=i;
}
}
else
{
if (a[p]==b[i])
{
if (p==strlen(a)-1)
{
ok=0;
x++;
y[l]=f;
l++;
b[f]='.';
}
else
p++;
}
else
{
p=0;
ok=0;
f=0;
}
}
i++;
}
int ex=0;
ok=0;i=0;p=0;f=0;
while (ex==0)
{
for (i=0;i<strlen(b);i++)
{
ex=1;
if (ok==0)
{
if (a[0]==b[i])
{
ok=1;
p=1;
f=i;
}
}
else
{
if (a[p]==b[i])
{
if (p==strlen(a)-1)
{
ok=0;
x++;
y[l]=f;
l++;
b[f]='.';
ex=0;
}
else
p++;
}
else
{
p=0;
ok=0;
f=0;
}
}
}
}
fout<<x;
fout<<'\n';
for (i=0;i<x;i++)
fout<<y[i]<<' ';
//c=a[0];
//int p,i=0,ok=0,x=0;
//while (p
//p=strchr(b,c);
fin.close();
fout.close();
return 0;
}