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!

Moderator: Board moderators
Code: Select all
___tom__hatess___jerry___,_____mickey loves goofy______
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
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;
}
According to my AC code:- 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).