HNU 10076 Jimmy's Riddles

Source: Internet
Author: User

HNU_10076

This is very similar to POJ's 3332. It is used to determine whether a string is valid. For details, refer to my other question.

#include<stdio.h>
#include<string.h>
#define MAXD 10010
char noun[][10] = {"tom", "jerry", "goofy", "mickey", "jimmy", "dog", "cat", "mouse"};
char verb[][10] = {"hate", "love", "know", "like", "hates", "loves", "knows", "likes"};
char b[MAXD], word[MAXD];
int pat;
void delword(int &i)
{
while(b[i] && b[i] != ' ')
++ i;
}
void delblank(int &i)
{
while(b[i] == ' ')
++ i;
}
int find_article()
{
if(strcmp(word, "a") == 0 || strcmp(word, "the") == 0)
return 1;
return 0;
}
int find_noun()
{
int i;
for(i = 0; i < 8; i ++)
if(strcmp(noun[i], word) == 0)
return 1;
return 0;
}
int find_verb()
{
int i;
for(i = 0; i < 8; i ++)
if(strcmp(verb[i], word) == 0)
return 1;
return 0;
}
void pattern()
{
if(pat == 0)
{
if(find_article())
pat = 1;
else
pat = 2;
}
else if(pat == 1)
{
pat = 2;
}
else if(pat == 2)
{
if(strcmp(word, "and") == 0)
pat = 3;
else
pat = 4;
}
else if(pat == 3)
{
if(find_article())
pat = 1;
else
pat = 2;
}
else if(pat == 4)
{
if(find_article())
pat = 5;
else
pat = 6;
}
else if(pat == 5)
{
pat = 6;
}
else if(pat == 6)
{
if(strcmp(word, "and") == 0)
pat = 7;
else
pat = 0;
}
else if(pat == 7)
{
if(find_article())
pat = 5;
else
pat = 6;
}
}
int check()
{
if(pat == 0)
{
if(strcmp(word, ",") == 0)
return 1;
else
return 0;
}
else if(pat == 1)
{
if(find_article())
return 1;
else
return 0;
}
else if(pat == 2)
{
if(find_noun())
return 1;
else
return 0;
}
else if(pat == 3)
{
if(strcmp(word, "and") == 0)
return 1;
else
return 0;
}
else if(pat == 4)
{
if(find_verb())
return 1;
else
return 0;
}
else if(pat == 5)
{
if(find_article())
return 1;
else
return 0;
}
else if(pat == 6)
{
if(find_noun())
return 1;
else
return 0;
}
else if(pat == 7)
{
if(strcmp(word, "and") == 0)
return 1;
else
return 0;
}
return 0;
}
int solve()
{
int i, j, k;
gets(b);
pat = 0;
for(i = 0, delblank(i); b[i];)
{
sscanf(b + i, "%s", word);
pattern();
if(!check())
return 0;
delword(i);
delblank(i);
}
if(pat == 6)
return 1;
else
return 0;
}
int main()
{
int t;
gets(b);
sscanf(b, "%d", &t);
while(t --)
{
if(solve())
printf("YES I WILL\n");
else
printf("NO I WON'T\n");
}
return 0;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.