At first , my solution is not consider space and it is wrong.some my test input
------>only contain '\n'
------>only contain '\n'
------>contain one space and '\n'
------>contain two spaces and '\n'
123
321
abba
bbaa
output
0
1
1
3
Is anthing wrong?
10405 - Longest Common Subsequence
Moderator: Board moderators
-
- Learning poster
- Posts: 67
- Joined: Sun Sep 22, 2002 5:40 am
- Location: Taiwan
10405 - Longest Common Subsequence
Last edited by Ghost77 dimen on Tue Nov 12, 2002 4:10 am, edited 1 time in total.
-
- Problemsetter
- Posts: 22
- Joined: Tue Jun 11, 2002 12:35 am
10405:who can tell me why?wrong answer...impossible....
[cpp]
void readData()
{
while(infile>>a>>b)
{
outfile<<maxCommonString()<<endl;
}
}
int maxCommonString()
{
int i,j;
int m=a.size();
int n=b.size();
for(i=0;i<up;i++)
for(j=0;j<up;j++)
c[j]=0;
for(int i=1;i<=m;i++)
c[0]=0;
for(int i=1;i<=n;i++)
c[0]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if (a[i-1]==b[j-1])
c[j]=c[i-1][j-1]+1;
else
if (c[i-1][j]>=c[j-1])
c[j]=c[i-1][j];
else
c[j]=c[j-1];
}
return c[m][n];
}
[/cpp]
void readData()
{
while(infile>>a>>b)
{
outfile<<maxCommonString()<<endl;
}
}
int maxCommonString()
{
int i,j;
int m=a.size();
int n=b.size();
for(i=0;i<up;i++)
for(j=0;j<up;j++)
c[j]=0;
for(int i=1;i<=m;i++)
c[0]=0;
for(int i=1;i<=n;i++)
c[0]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
if (a[i-1]==b[j-1])
c[j]=c[i-1][j-1]+1;
else
if (c[i-1][j]>=c[j-1])
c[j]=c[i-1][j];
else
c[j]=c[j-1];
}
return c[m][n];
}
[/cpp]
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
if a string has nothing....
![:(](./images/smilies/icon_frown.gif)
i've never thought about the condition of a string null....
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
10405 again
What's wrong with this...:
[cpp]#include <iostream.h>
#include <string.h>
void main()
{
char* str=new char[1100];
char* str2=new char[1100];
while (!cin.eof())
{
/*char ch;
while (cin.get(ch) && (ch==' '))
{}
if (cin.eof())
break;
cin.putback(ch);
ch=0;
while (cin.get(ch) && (ch==' '))
{}
cin.putback(ch);*/
cin.getline(str,1100,'\n');
cin.getline(str2,1100,'\n');
int max=0;
int i,j,count;
int len=strlen(str);
int len2=strlen(str2);
for (i=0;i<len;i++)
{
j=0;
count=0;
int pivot1=i;
int pivot2=0;
while (pivot1<len)
{
j=pivot2;
while (j<len2 && str2[j]!=str[pivot1])
j++;
if (j<len2)
{
j++;
count++;
pivot1++;
pivot2=j;
}
else
{
pivot1++;
j=pivot2;
}
}
if (count>max)
max=count;
}
cout<<max<<endl;
}
}
[/cpp]
[cpp]#include <iostream.h>
#include <string.h>
void main()
{
char* str=new char[1100];
char* str2=new char[1100];
while (!cin.eof())
{
/*char ch;
while (cin.get(ch) && (ch==' '))
{}
if (cin.eof())
break;
cin.putback(ch);
ch=0;
while (cin.get(ch) && (ch==' '))
{}
cin.putback(ch);*/
cin.getline(str,1100,'\n');
cin.getline(str2,1100,'\n');
int max=0;
int i,j,count;
int len=strlen(str);
int len2=strlen(str2);
for (i=0;i<len;i++)
{
j=0;
count=0;
int pivot1=i;
int pivot2=0;
while (pivot1<len)
{
j=pivot2;
while (j<len2 && str2[j]!=str[pivot1])
j++;
if (j<len2)
{
j++;
count++;
pivot1++;
pivot2=j;
}
else
{
pivot1++;
j=pivot2;
}
}
if (count>max)
max=count;
}
cout<<max<<endl;
}
}
[/cpp]
can anyone tell me some test input and the correct output?
what's the output of
what's the output of
Code: Select all
abckkkbbbcccbbbddd
abbbcccd
?fiweuhvnwjs
27hwnfguhewru43?
please help
what about this test input
Code: Select all
aabcccddd
abdddcccddd
aabccccdddcccddd
abcccddd
??? jake
jak?e??
crajudzyge
crazyjudge
hehehehe :)
eheheheh ):
-
- New poster
- Posts: 5
- Joined: Sun Feb 23, 2003 7:33 pm
WAWAWA!!!
I've tried all test data i can find..
but still got a WA!
can anyone take a look on my code?
but still got a WA!
can anyone take a look on my code?
![:cry:](./images/smilies/icon_cry.gif)
Code: Select all
[color=blue][/color]
#include<stdio.h>
#include<string.h>
int main()
{
int length1,length2,i,j,k;
char temp,arr1[1001],arr2[1001];
while (gets(arr1))
{
int max=0,count,temp;
gets(arr2);
length1=strlen(arr1);
length2=strlen(arr2);
for (i=0;i<length1;i++)
{
count=0;
temp=0;
for (j=i;j<length1;j++)
{
for (k=temp;k<length2;k++)
{
if (arr1[j]==arr2[k])
{
count++;
temp=k+1;
break;
}
}
}
if (count>max)
max=count;
}
printf("%d\n",max);
}
}