10340 - All in All

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10340 - All in All

Post by brianfry713 » Tue Jun 12, 2012 11:19 pm

You're printing an extra newline at the end of the output.
Check input and AC output for thousands of problems on uDebug!

sith
Learning poster
Posts: 72
Joined: Sat May 19, 2012 7:46 pm

Re: 10340 - All in All

Post by sith » Wed Jun 13, 2012 11:43 pm

Thanks a lot!!!

hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

Re: 10340 - All in All

Post by hello » Tue Jul 30, 2013 1:12 am

Why the LCS algo giving Runtime error. Ya i have already solved it in other way. Byt LCS should work. Is there any problem with my code? I see other people have the same problem.

Code: Select all

 ? 

sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

10340 WA

Post by sajal2k8 » Thu Nov 28, 2013 6:51 pm

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
long long int l,m,i,j,count=0,pos=-1;
string s,t;
while(cin>>s>>t)
{
l=s.size();
m=t.size();
for(i=0;i<l;i++)
{
for(j=0;j<m;j++)
{
if(s==t[j] && (pos<j))
{
count++;
pos=j;
break;
}

}
}
if(l==count)
cout<<"Yes";
else
cout<<"No";
cout<<"\n";
count=0;
pos=-1;
}
return 0;
}
What is the problem here?
And can anybody tell me for some critical input?
Thanks in advance

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10340 WA

Post by brianfry713 » Tue Dec 03, 2013 3:05 am

That is AC code
Check input and AC output for thousands of problems on uDebug!

cse dipto
New poster
Posts: 22
Joined: Tue Oct 29, 2013 6:46 pm

Re: 10340 WA pls help iam just fed up

Post by cse dipto » Sat Jan 04, 2014 3:55 pm

Code: Select all

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <map>
#include <vector>


using namespace std;

int main()
{
    int i,j,k,t_case,len,len2,index;
    char a[100000],s[100000];
    while(scanf("%s",&a)==1)
    {
        scanf("%s",&s);
        len=strlen(a);
        len2=strlen(s);
        int check=0;
        int temp=0;
        int check2=0;
        for(i=0;i<len;i++)
        {
            for(j=temp;j<len2;j++)
            {
                if(a[i]==s[j])
                {
                    check++;
                    check2=1;
                    temp=j;
                    break;
                }
                if(a[i+1]==s[j])
                {
                    check2=0;
                    break;
                }
            }
            if(check2==0)
            {
                break;
            }
        }
        if(check==len&&check2==1)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10340 WA

Post by brianfry713 » Wed Jan 15, 2014 1:26 am

Try input ba aba
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Why WA with UVa 10340- All in All

Post by Shahidul.CSE » Tue Jul 15, 2014 6:03 pm

I don't understand why I am having WA with my code.

My code:

#include<stdio.h>
#include<string.h>
int main()
{
//freopen("10340.txt", "r", stdin);
char subs[1039999],mains[1039999],ch;
long long int i,j,val;
while(scanf("%s %s",&subs,&mains) !=EOF)
{
j=val=0;
for(i=0;i<strlen(subs);i++)
{
ch=subs;
for(;j<strlen(mains);j++)
{
if(ch==mains[j])
{
val++;
break;
}
}
}
if(val==strlen(subs))
printf("Yes\n");
else printf("No\n");

}
return 0;
}
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

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Why having WA with UVa 10340- All in All

Post by Shahidul.CSE » Tue Jul 15, 2014 6:06 pm

I don't understand why I am having WA with my code.

code removed after got ac
Last edited by Shahidul.CSE on Wed Jul 16, 2014 2:52 pm, 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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why WA with UVa 10340- All in All

Post by brianfry713 » Tue Jul 15, 2014 7:37 pm

Don't double post.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Why having WA with UVa 10340- All in All

Post by brianfry713 » Tue Jul 15, 2014 7:50 pm

Input: aa a
Output should be No
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: Why having WA with UVa 10340- All in All

Post by Shahidul.CSE » Tue Jul 15, 2014 8:26 pm

I changed my code as below. Now I am getting output "NO" for input "aa a" but even WA. I added another condition that when length of sub sequence is greater than main sequence, then print NO.

Code removed after getting ac
Last edited by Shahidul.CSE on Wed Jul 16, 2014 3:18 pm, 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

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

Re: Why having WA with UVa 10340- All in All

Post by lbv » Tue Jul 15, 2014 9:26 pm

Shahidul.CSE wrote:I changed my code as below. Now I am getting output "NO" for input "aa a" but even WA. I added another condition that when length of sub sequence is greater than main sequence, then print NO.
Notice that the output from your program should match the expected output exactly. The strings "NO" and "No" are considered different.

Also try:

Input

Code: Select all

caaaadd dbaacdabbdccacab
faa aceecbeeffaeeced
Output

Code: Select all

No
No

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: Why having WA with UVa 10340- All in All

Post by lighted » Tue Jul 15, 2014 11:09 pm

As lbv pointed change one letter

Code: Select all

if(strlen(subs)>strlen(mains))
            printf("NO\n");
It must be

Code: Select all

if(strlen(subs)>strlen(mains))
            printf("No\n");
Add one line

Code: Select all

else if(ch==mains[j])
                {
                    val++;
                    break;
                }
                ++j;
            }
        }
It must be

Code: Select all

else if(ch==mains[j])
                {
                    val++;
                    break;
                }
                ++j;
            }
            ++j;
        }
You forget to increase j after it become equal to ch.
When letter of first string matches (equals) a letter of second string they both must move to next letters.
But you don't move second strings letter. :wink:
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: Why having WA with UVa 10340- All in All

Post by Shahidul.CSE » Tue Jul 15, 2014 11:55 pm

Thank you !! Got accepted !!!
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

Post Reply

Return to “Volume 103 (10300-10399)”