10058 - Jimmi's Riddles

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

Moderator: Board moderators

LittleJohn
Learning poster
Posts: 83
Joined: Wed Feb 27, 2002 2:00 am
Location: Taiwan

Post by LittleJohn » Sat Mar 23, 2002 11:48 am

Hello:
I try to solve this problem, but I got so many WA and don't know why. Any tricks or something I may lose? please tell me, thank you very much! :smile:

Anderson
New poster
Posts: 6
Joined: Thu Apr 18, 2002 12:47 pm

Try these test cases

Post by Anderson » Mon Apr 29, 2002 10:50 am

tom hates jerry ,, jimmy hates tom
jimmy
a hate
jimmy hates tom ,
jimmy hate
tom hates jerry , jimmy hates tom
hates
jimmy hates tom
hate hate hate

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

output

Post by Subeen » Sun Aug 18, 2002 4:09 am

my prog produces the following outputs for ur given input and of course it got WA:

NO I WON’T
NO I WON’T
NO I WON’T
NO I WON’T
NO I WON’T
YES I WILL
NO I WON’T
YES I WILL
NO I WON’T


what's wrong?

Even
Learning poster
Posts: 75
Joined: Thu Nov 22, 2001 2:00 am
Location: Taiwan

WA?

Post by Even » Sun Aug 18, 2002 12:38 pm

this is my output according to the input above...

NO I WON

Even
Learning poster
Posts: 75
Joined: Thu Nov 22, 2001 2:00 am
Location: Taiwan

hi...

Post by Even » Sun Aug 18, 2002 4:49 pm

Hello...Subeen...

try this case ...

tom and tom and tom hatessssssssss tom , tom hates tom
tom lovesssssssss jimmy

both should be "YEW I WILL"...

tom like jum

should be "NO I WON'T" .... not "NO I WON

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Mon Aug 19, 2002 12:55 pm

thankx... I got it AC. :D

Yarin
Problemsetter
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume
Contact:

Post by Yarin » Sat Sep 21, 2002 4:21 am

I'm getting WA on this one all the time, although it works on all inputs in this thread. Are the whitespace supposed to be exactly according to the formula, or may there be extra whitespace anywhere, like end of the line etc. Same thing, between two actions, should there always be exactly [space] [comma] [space]. Also, the ' character in "WON'T", which ASCII char is that anyway!? Doing a copy & paste from the problem description seems to indicate it's not the default ' character... but I'm not sure whether to trust the problem description.

LittleJohn
Learning poster
Posts: 83
Joined: Wed Feb 27, 2002 2:00 am
Location: Taiwan

Post by LittleJohn » Sat Sep 21, 2002 5:25 am

Hello, Yarin
I used strtok to parse the input string. Thus we can ignore extra whitespace anywhere. And, you're right, there will be exactly [spaces] [comma] [spaces]. Besides, you shouldn't copy & paste the ' character in sample output, just type ' and it will be fine. :wink:

arc16
Learning poster
Posts: 62
Joined: Sun Aug 04, 2002 1:05 am
Location: Indonesia

Post by arc16 » Sat Sep 21, 2002 5:33 am

hi,
yes, there might be LOT OF whitespace, including before eol.
so there would be something like:

Code: Select all

___tom__hatess___jerry___,_____mickey loves goofy______
'_' is whitespace
In the WON'T, it's ascii #39.

you could also try this:

Code: Select all

mickey lovess goofy and jerry , tom loves goofy and mickey and jerry,the jerry loves a goofy and a tom and a mickey and the jerry and the tom and the mickey and a jerry and a tom and a mickey,  tom loves a cat  ,jerry loves a dog
the answer is YES

Yarin
Problemsetter
Posts: 112
Joined: Tue Sep 10, 2002 5:06 am
Location: Ume
Contact:

Post by Yarin » Sat Sep 21, 2002 4:13 pm

Thanks, got AC finally!

Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:

10058-need I/O

Post by Zuberul » Mon Nov 21, 2005 7:13 pm

please give me some I/O.

thanks in advance.

Zuberul
New poster
Posts: 28
Joined: Sun Oct 24, 2004 9:46 pm
Location: dhaka
Contact:

Post by Zuberul » Tue Nov 22, 2005 6:20 pm

:D had a little refresh problem.
got AC.

Johan
New poster
Posts: 7
Joined: Wed Dec 21, 2005 5:27 pm

10058 - WA

Post by Johan » Wed Oct 04, 2006 3:24 am

Hi,

I was wondering if someone might have some good testcases for my code. I was confused by:

- the extra words that seem to be in the input (I chose to regard them as wrong rather than ignore them)
- the apostroph in the output (I just copied it from the example output, even though it seems to have ascii value > 127)
- the "VERBs" in the definition of VERB (I chose to consider a given verb with any number of characters 's' behind it to be correct).

I hope someone can help me. :)

Kind regards,

Johan

Code: Select all

#include <iostream> 
#include <sstream> 
#include <string> 
#include <vector> 
#include <queue> 
#include <set> 
#include <map> 
#include <cstdio> 
#include <cstdlib> 
#include <cctype> 
#include <cmath> 
#include <list> 
#include <algorithm>
#include <numeric>
using namespace std; 


 // pre-written code
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<string> vs; 
typedef vector<vs> vvs;
#define pb push_back 
#define sz(v) ((int)(v).size()) 


vs splitvs(string s,string split)
{
  vs uit; string nu;
  split+=char(0); s+=char(0);
  for(int i=0;i<sz(s);i++)
  {
    if(split.find(s[i])!=string::npos)
    { if(sz(nu))uit.pb(nu); nu=""; }
    else nu+=s[i];
  }
  return uit;
}


vs NOUN, VERB;


bool isACTIVE_LIST(vs actlist)
{
  string res; int j;
  for(j=0;j<sz(actlist);j++)
    if(actlist[j]=="and")
      res+="&"; 
    else if(actlist[j]=="a"||actlist[j]=="the")
      res+="a";
    else if(find(NOUN.begin(),NOUN.end(),actlist[j])!=NOUN.end())
      res+="n";
    else
      return false;
  
  res="&"+res+"&";
  for(j=0;j<sz(res)-1;j++)
    if(res[j]=='&'&&res[j+1]=='&')
      return false;
 
  vs rr=splitvs(res,"&");
  for(j=0;j<sz(rr);j++)
    if(rr[j]!="n"&&rr[j]!="an")
      return false;

  return true;
}


bool isACTION(string action)
{
  vs act=splitvs(action," ");
  int j,cnt=0,pos;
  for(j=0;j<sz(act);j++)
  {
    string strip=act[j];
    while(sz(strip)&&strip[sz(strip)-1]=='s') 
      strip=strip.substr(0,sz(strip)-1);
    if(find(VERB.begin(),VERB.end(),strip)!=VERB.end())
    {
      cnt++;
      pos=j;
    }
  }

  if(cnt!=1||pos==0||pos==sz(act)-1)
    return false;

  vs left,right;
  for(j=0;j<sz(act);j++)
    if(j<pos)
      left.pb(act[j]);
    else if(j>pos)
      right.pb(act[j]);

  return isACTIVE_LIST(left)&&isACTIVE_LIST(right);
}


char buf[1000000];
int main()
{
  int N,M,i,j,k;

  NOUN = splitvs("tom|jerry|goofy|mickey|jimmy|dog|cat|mouse","|");
  VERB = splitvs("hate|love|know|like","|");
  
  while(gets(buf))
  {
    string input=buf; if(sz(input)==0) break;
    vs actions=splitvs(input,",");
    
    bool allActions=true;
    for(j=0;j<sz(actions);j++)
      allActions&=isACTION(actions[j]);
    printf("%s\n",allActions?"YES I WILL":"NO I WON’T");
  }
  
  return 0;
}

Solaris
Learning poster
Posts: 99
Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:

Post by Solaris » Thu Nov 02, 2006 8:40 am

- the extra words that seem to be in the input (I chose to regard them as wrong rather than ignore them)
- the apostroph in the output (I just copied it from the example output, even though it seems to have ascii value > 127)
- the "VERBs" in the definition of VERB (I chose to consider a given verb with any number of characters 's' behind it to be correct).
According to my AC code:

1. Presence of extra word is wrong
2. apostrophy is NORMAL apostrophy
3. Your defn of VERB is the same as mine
Where's the "Any" key?

sakhassan
Experienced poster
Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

Post by sakhassan » Thu Mar 01, 2007 10:42 am

Can anyone give me some critical input/output ?

Thanks in Advance
Time that gone is gone forever ...

Post Reply

Return to “Volume 100 (10000-10099)”