10340 - All in All

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

Moderator: Board moderators

Postby DanielMarques » Wed Feb 13, 2008 10:25 pm

It worked! :D
Thanks sapnil
DanielMarques
New poster
 
Posts: 5
Joined: Thu Jan 24, 2008 7:13 pm
Location: Rio de Janeiro

why is my programm giving WA

Postby fR0D » Sun Feb 24, 2008 7:24 am

here's my code..i cant understand y it gives WA plz help..
Code: Select all
#include<iostream>
using namespace std;
#include<string.h>

int main()
{
    char str1[1000000],str2[1000000];
    int l1,l2,i,j,FLAG=1;
    while (scanf("%s%s",str1,str2)!=EOF)
    {
          FLAG=1;
          l1=strlen(str1);
          l2=strlen(str2);
          for (i=0,j=0;i<l1 && j<l2 && l1<=l2;i++)
          {
              for (;j<l2;j++)
                   if (str1[i]==str2[j])     
                   {   
                      j++;
                      break;
                   }
          }                   
          if(i!=l1 || (l1==l2 && strcmp(str1,str2)!=0))
                   FLAG=0;
          if(FLAG==0)
                     printf("No\n");
          else
              printf("Yes\n");
    }
}
fR0D
New poster
 
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am

Postby fR0D » Sun Feb 24, 2008 7:28 am

what is the output in case of
input:

abc abc
fR0D
New poster
 
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am

Postby Jan » Tue Feb 26, 2008 5:41 pm

Yes.
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

Postby fR0D » Wed Feb 27, 2008 9:14 am

can u give some tricky cases or figur out why my program gives WA??
fR0D
New poster
 
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am

Postby Jan » Wed Feb 27, 2008 9:00 pm

Try the case.

Input:
Code: Select all
abcc abcdddd

Output:
Code: Select all
No

Hope it helps.
Jan
Guru
 
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh

10340 - WA

Postby diegororiz » Fri May 23, 2008 10:50 pm

I've got a RE and i do'nt know why!
If anybody can help me!!

Code: Select all
Got acc


thks!
Last edited by diegororiz on Thu Jul 17, 2008 12:41 am, edited 1 time in total.
diegororiz
New poster
 
Posts: 1
Joined: Fri May 23, 2008 10:44 pm

Re:

Postby The_Madman » Mon Jun 02, 2008 12:02 pm

asif_rahman0 wrote:Array size should be 1000000.


thanx bro....it really helped and now's been accepted. but here comes a question....how can one assume the length of these string type questions...some days ago...i was stuck by this same kind of prob..while the algo was ok..it needed to change the string length to 1000 so this time i thought 1000 is sufficient..but alas!

do you know anything regarding it?
The_Madman
New poster
 
Posts: 12
Joined: Fri May 23, 2008 10:24 pm

WA pls help

Postby theharshest » Thu Jul 17, 2008 12:17 am

I am getting WA for this code -- pls help :(

Code: Select all
#include<iostream>
#include<string>

using namespace std;

int main()
{

string s,t;

long i,j;

while(cin>>s>>t)
{
 i=0;
 j=0;
 while(1)
 {
  if(s[i]==t[j])
  {
  if(s[i-1]==t[j-1] || i==0 || j==0)
   {i++;
   j++;}
   else
   j++;
  }         
  else
   j++;
 
 //cout<<s[i]<<" "<<t[j]<<endl;
  if(i==(s.length()) || j==(t.length()))
  break;             
 }
 if(i==(s.length()))
 cout<<"Yes"<<endl;
 else
 cout<<"No"<<endl;
 
}   

}
"if u r goin thru hell, keep goin"
User avatar
theharshest
New poster
 
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

Re: 10340 - All in All

Postby rio » Mon Jul 28, 2008 6:23 am

Your code doesn't even pass the sample io.
Try to output it correctly, and you'll understand wheres your mistake is.

-----
Rio
User avatar
rio
A great helper
 
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Re: 10340 - All in All

Postby fjfj » Fri Nov 26, 2010 11:52 pm

why WA???
please help!! :cry: :cry:
Code: Select all
#include <stdio.h>
#include <string.h>
char *s1,*s2,s[2000010];
int main()
{
   char flag,i,j,l1,l2,k;
   while (gets(s)!=NULL)
   {
      s1=strtok(s," ");
      s2=strtok(NULL," ");
      l1=strlen(s1);
      l2=strlen(s2);
      if (l1>l2)
      {
         printf("No\n");
         continue;
      }
      else if (strstr(s1,s2)!=NULL)
      {
         printf("Yes\n");
         continue;
      }
      else
      {
         k=0;
         for (i=0;s1[i]!='\0';i++)
         {
            flag=0;
            for (j=k;s2[j]!='\0';j++)
            {
               if (s1[i]==s2[j])
               {
                  flag=1;
                  s2[j]=' ';
                  k=j;
                  break;
               }
            }
            if (flag==0)
               break;
         }
         if (flag==0)
            printf("No\n");
         else if (flag==1)
            printf("Yes\n");
      }
   }
   return 0;
}
fjfj
New poster
 
Posts: 1
Joined: Fri Nov 26, 2010 11:48 pm

Re: 10340 - All in All

Postby sith » Mon Jun 11, 2012 11:50 pm

Hello!
I've got WA but I believe that my solution is correct. All cases from this thread, proof it.

Here is my code

Code: Select all
AC


Helppppppp!
Last edited by sith on Wed Jun 13, 2012 11:43 pm, edited 1 time in total.
sith
Learning poster
 
Posts: 67
Joined: Sat May 19, 2012 7:46 pm

Re: 10340 - All in All

Postby brianfry713 » Tue Jun 12, 2012 11:19 pm

You're printing an extra newline at the end of the output.
brianfry713
Guru
 
Posts: 1761
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10340 - All in All

Postby sith » Wed Jun 13, 2012 11:43 pm

Thanks a lot!!!
sith
Learning poster
 
Posts: 67
Joined: Sat May 19, 2012 7:46 pm

Previous

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 1 guest