Cod sursa(job #443479)

Utilizator ursu-valiJerdea Florin ursu-vali Data 17 aprilie 2010 00:21:30
Problema Subsir Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<Stdio.h>
#include<string.h>
# define Nmax 520
char a[Nmax];
char b[Nmax];
long c[Nmax];
long na,nb,lg,nrlg,lgmax;
void read(void)
{
	fgets(a,520,stdin);
	na=strlen(a);
	fgets(b,520,stdin);
	nb=strlen(b);
}
void solve()
{
	long i,j,lg,max;
	for(i=0;i<nb;i++)
	{
		lg=0;
		for(j=0;j<na;j++)
			if((b[i]==a[j])&&(c[j]==0))
			{
				c[j]=lg+1;
				break;
			}
			else
				if(c[j]>lg)
					lg=c[j];
	}
	max=0;
	for(i=0;i<na;i++)
		if(c[i]>max)
		{
			max=c[i];
			lg=1;
		}
		else
			if(c[i]==max)
				lg++;
	printf("%ld",lg);		
}
int main()
{
	freopen("subsir.in","r",stdin);
	freopen("subsir.out","w",stdout);
	read();
	solve();
	fclose(stdin);
	fclose(stdout);
	return 0;
}