10100 - Longest Match
Moderator: Board moderators
Re: 10100 - Longest Match
my code also gives the same output.... but why wa..........
-
- Experienced poster
- Posts: 147
- Joined: Mon Jun 07, 2010 11:43 am
- Location: University Of Dhaka,Bangladesh
- Contact:
Re: 10100 - Longest Match
@Fkrali:
Your code will produce wrong output in this case:
Your output is 1 where it should be 0. just ignore capital letters and you'll get ac.
Your code will produce wrong output in this case:
Code: Select all
hello world
HELLO
UVa stats: http://felix-halim.net/uva/hunting.php?id=63448
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
My blog on programming: http://www.shafaetsplanet.com/planetcoding/
Re: 10100 - Longest Match
Hi, could you help me here? I keep getting runtime error and I don't know why.
Thanks a lot!
Code: Select all
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <string.h>
using namespace std;
string arr1[1002];
string arr2[1002];
int arrDef[1002][1002];
int procesarLinea (string a, string arr[1002]);
int main()
{
int cont = 1;
string a, b;
while (getline(cin, a))
{
memset(arrDef, 0, sizeof arrDef);
memset(arr1, 0, sizeof arr1);
memset(arr2, 0, sizeof arr2);
int numPalabras1, numPalabras2;
getline(cin, b);
if (a.size() == 0 || b.size() == 0)
{
cout << cont << ". Blank!" << endl;
}
else
{
int numLetras = 0;
string::iterator it = a.begin();
for (int i = 0; i < a.size(); i++)
{
if (numLetras == 0 && a[i] == ' ')
{
a.erase(it);
i=-1;
}
else if (isalnum(a[i]))
{
numLetras++;
it++;
}
else if (numLetras > 0 && a[i] == ' ' && i < a.size()-1 && a[i+1] == ' ')
{
a.erase(it);
i--;
}
else it++;
}
numLetras = 0;
it = b.begin();
for (int i = 0; i < b.size(); i++)
{
if (numLetras == 0 && b[i] == ' ')
{
b.erase(it);
i = -1;
}
else if (isalnum(b[i]))
{
numLetras++;
it++;
}
else if (numLetras > 0 && b[i] == ' ' && i < b.size()-1 && b[i+1] == ' ')
{
b.erase(it);
i--;
}
else it++;
}
numPalabras1 = procesarLinea(a, arr1);
numPalabras2 = procesarLinea(b, arr2);
for (int i = 1; i <= numPalabras1; i++)
{
for (int j = 1; j <= numPalabras2; j++)
{
if (arr1[i-1] == arr2[j-1])
{
arrDef[i][j] = arrDef[i-1][j-1] + 1;
}
else
{
arrDef[i][j] = max (arrDef[i][j-1], arrDef[i-1][j]);
}
}
}
cout << cont << ". Length of longest match:";
cout << setw(2);
cout << arrDef[numPalabras1][numPalabras2] << endl;
}
cont++;
}
return 0;
}
int procesarLinea (string a, string arr[1002])
{
int numPalabras = 1;
int numPalabrasDef = 0;
for (int i = 0; i < a.size(); i++)
{
if (a[i] >= 'A' && a[i] <= 'Z')
{
numPalabrasDef = numPalabras;
a[i] = tolower(a[i]);
arr[numPalabras-1] = arr[numPalabras-1] + a[i];
}
else if (isalnum(a[i]))
{
numPalabrasDef = numPalabras;
arr[numPalabras-1] = arr[numPalabras-1] + a[i];
}
else
{
numPalabras++;
}
}
return numPalabrasDef;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
On the sample input your code is producing a seg fault during procesarLinea().
Check input and AC output for thousands of problems on uDebug!
why this code give me Presentation error every time :(
finaly AC...
thank you Mr brianfry713 very much
thank you Mr brianfry713 very much

Last edited by asmaa on Thu Jul 11, 2013 2:31 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
you have to output a line starting with the case number right justified in a field width of two
Check input and AC output for thousands of problems on uDebug!
Re: 10100 - Longest Match
cout<<count<<". Length of longest match: "<<LCS[v2.size()][v1.size()]<<endl;
what is wrong with this?
what is wrong with this?
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
For the sample input, your output is:The correct output is:
Code: Select all
1. Length of longest match: 1
2. Blank!
3. Length of longest match: 2
Code: Select all
1. Length of longest match: 1
2. Blank!
3. Length of longest match: 2
Check input and AC output for thousands of problems on uDebug!
Re: 10100 - Longest Match
I made it :
cout<<" "<<count<<". Blank!"<<endl; and cout<<" "<<count<<". Length of longest match: "<<LCS[v2.size()][v1.size()]<<endl;
but i still have PE
cout<<" "<<count<<". Blank!"<<endl; and cout<<" "<<count<<". Length of longest match: "<<LCS[v2.size()][v1.size()]<<endl;
but i still have PE

-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
Try input:Output should be:
Code: Select all
This is a test.
test
Hello!
The document provides late-breaking information
late breaking.
This is a test.
test
Hello!
The document provides late-breaking information
late breaking.
This is a test.
test
Hello!
The document provides late-breaking information
late breaking.
This is a test.
test
Hello!
The document provides late-breaking information
late breaking.
Code: Select all
1. Length of longest match: 1
2. Blank!
3. Length of longest match: 2
4. Length of longest match: 1
5. Blank!
6. Length of longest match: 2
7. Length of longest match: 1
8. Blank!
9. Length of longest match: 2
10. Length of longest match: 1
11. Blank!
12. Length of longest match: 2
Check input and AC output for thousands of problems on uDebug!
Re: 10100 - Longest Match
why wa plz help me........
Code: Select all
thank you brianfry713
Last edited by jalil_cse on Sun Dec 22, 2013 5:57 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
output a line starting with the case number right justified in a field width of two
Check input and AC output for thousands of problems on uDebug!
Re: 10100 - Longest Match
Code: Select all
AC
Re: 10100 - Longest Match
I guess we are counting words which gets matches, even uDebug gives output 1.brianfry713 wrote:Input:Output should be 2.a!aa!aaa!
aa
Output should be 1.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10100 - Longest Match
Yes, that output should be 1.
Try input:AC output:
Try input:
Code: Select all
The document provides late-breaking information
late breaking.
aaa a a a a
a
Code: Select all
1. Length of longest match: 2
2. Length of longest match: 1
Check input and AC output for thousands of problems on uDebug!