531 - Compromise
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise - WA
You're printing a null character at the end of each line.
Check input and AC output for thousands of problems on uDebug!
Re: 531 - Compromise - WA
Last edited by TLEorWA on Fri Jun 13, 2014 11:21 pm, edited 1 time in total.
Why WA? I solved by DP - LCS
sorry. look to next post
Last edited by lighted on Sun Jun 15, 2014 1:42 pm, edited 5 times in total.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise - WA
TLEorWA, Try the input
#
#
My AC code prints nothing, not even a blank line.
#
#
My AC code prints nothing, not even a blank line.
Check input and AC output for thousands of problems on uDebug!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise - WA
lighted, try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!
Re: 531 - Compromise - WA
I've changed my code. But wa. Maybe some problems with reading strings. Who can give some input tests?
In one day third time i make same full mistake, not removing comments and read/write from files.
// #ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
// #endif
Code: Select all
removed, after acc...
// #ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
// #endif
Last edited by lighted on Tue Jun 17, 2014 4:26 pm, edited 2 times in total.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise - WA
Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!
Re: 531 - Compromise PE error
I have tried every input Pleae Help .
@briyanfry
Thanks.. Please Help..
![:oops:](./images/smilies/icon_redface.gif)
Code: Select all
/*
Approach: Longest Common Subsequence
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#include<stack>
#include<queue>
#define PI 3.14159265
#define M 1000000007
#define EPS 1e-9
#define ll long long int
using namespace std;
const int N = 1000005;
int a[3005][3005];
vector<string>v;
int main()
{
//freopen("input.txt","r",stdin);
string s0;
while(getline(cin,s0))
{
if(s0.size()==0)break;
//cout<<" fuck "<<endl;
string s1[105]="",s2[105]="",s;int len1=0,len2=0;
//int c=0;
v.clear();
for(int i=0;i<s0.size();i++)
{
if(s0=="#")break;
if(s0[i]==' ')
{
//cout<<s1[len1] <<" ";
len1++;continue;
}
s1[len1]+=s0[i];
//len1++;
}
//cout<<s1[len1] <<endl;
len1++;
while(1 && s0!="#")
{
//cout<<"fuck"<<endl;
getline(cin,s);
if(s=="#")break;
for(int i=0;i<s.size();i++)
{
if(s[i]==' ')
{
// cout<<s1[len1] <<" ";
len1++;continue;
}
s1[len1]+=s[i];
}
len1++;
}
//cout<<s1[0]<<endl;
while(1)
{
getline(cin,s);
if(s=="#" || s.size()==0)break;
//if(s.size()>0)
//cout<<"funm?"<<endl;
for(int i=0;i<s.size();i++)
{
// cout<<"fuck"<<endl;
if(s[i]==' ')
{
len2++;continue;
}
s2[len2]+=s[i];
}
len2++;
}
//cout<<s1[len1-1]<<" " <<s2[len2-1]<<endl;
for(int i=0;i<len1;i++)
{
a[i][0]=0;
}
for(int j=0;j<len2;j++)
{
a[0][j]=0;
}
for(int i=1;i<=len1;i++)
{
for(int j=1;j<=len2;j++)
{
if(s1[i-1]==s2[j-1])
{
a[i][j]=a[i-1][j-1]+1;
}
else
{
a[i][j]=max(a[i-1][j],a[i][j-1]);
}
}
}
int i=len1,j=len2;
//cout<<len1<<" k "<<len2<<endl;
while(i>0 &&& j>0)
{
// cout<<i<<endl;
if(a[i][j]==a[i-1][j])i--;
else if(a[i][j]==a[i][j-1])j--;
else
{
v.push_back(s1[i-1]);
i--;j--;
}
}
reverse(v.begin(),v.end());
if(v.size()>=1)
{
//cout<<v[0];
for(int i=0;i<v.size();i++)
{
cout<<v[i];
if(i!=v.size()-1)cout<<" ";
else
cout<<endl;
}
}
}
return 0;
}
Thanks.. Please Help..
![:)](./images/smilies/icon_smile.gif)
![:oops:](./images/smilies/icon_redface.gif)
![:oops:](./images/smilies/icon_redface.gif)
![:oops:](./images/smilies/icon_redface.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise
It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
Re: 531 - Compromise
No The above code is still getting PE .. Can you tell wts wrong in that code.
Please ..
Thanks
![:oops:](./images/smilies/icon_redface.gif)
Please ..
Thanks
![:oops:](./images/smilies/icon_redface.gif)
![:oops:](./images/smilies/icon_redface.gif)
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise
I saw on uhunt that you already got AC on this problem.
Try changing your input parsing. I got AC reading the input as strings, not line by line.
Try changing your input parsing. I got AC reading the input as strings, not line by line.
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 531 - Compromise
Code: Select all
Accepted !
Last edited by Shahidul.CSE on Sat Dec 13, 2014 5:51 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 531 - Compromise
Input:AC output:
Code: Select all
a b c d e
#
b c d e a
#
a b a a
#
a a
#
Code: Select all
b c d e
a a
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 531 - Compromise
Thanks, now got accepted ![:D](./images/smilies/icon_biggrin.gif)
![:D](./images/smilies/icon_biggrin.gif)
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com