⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2069.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 2069 on 2007-04-13 at 18:18:44 */
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

const char ARTICLE[][10] = { "a", "the", "" };
const char NOUN[][10] = { "tom", "jerry", "goofy", "mickey", "jimmy", "dog", "cat", "mouse", "" };
const char VERB[][10] = { "hate", "love", "know", "like", "" };

vector<string> s;
int ptr;

void token(char*);
bool statement();
bool action();
bool active_list();
bool actor();
bool article(bool);
bool noun();
bool verb();
bool stata();
bool alb();

int main()
{
	char str[2048];
	int T;
	
	scanf("%d\n", &T);
	for(int t = 0; t < T; t++) {
		token(gets(str));
		printf("%s\n", (statement() && ptr == s.size()) ? "YES I WILL" : "NO I WON'T");
	}
	
	return 0;
}

void token(char* str)
{
	s.clear(); ptr = 0;
	string st(str), tmp;
	stringstream ss(st);
	while(ss >> tmp) s.push_back(tmp);
}
bool statement()
{
	return action() && stata();
}
bool action()
{
	return active_list() && verb() && active_list();
}
bool active_list()
{
	return actor() && alb();
}
bool actor()
{
	if(article(true)) return article(false) && noun();
	else return noun();
}
bool article(bool test)
{
	if(ptr == s.size()) return false;
	bool res = false;
	for(int i = 0; ARTICLE[i][0] != 0; i++)
		if(s[ptr] == ARTICLE[i]) res = true;
	if(!test) ptr++;
	return res;
}
bool noun()
{
	if(ptr == s.size()) return false;
	bool res = false;
	for(int i = 0; NOUN[i][0] != 0; i++)
		if(s[ptr] == NOUN[i]) res = true;
	ptr++;
	return res;
}
bool verb()
{
	if(ptr == s.size()) return false;
	bool res = false;
	for(int i = 0; VERB[i][0] != 0; i++)
		if(s[ptr] == VERB[i] || s[ptr] == string(VERB[i])+'s') res = true;
	ptr++;
	return res;
}
bool stata()
{
	if(ptr == s.size()) return true;
	if(s[ptr] == ",") { ptr++; return action() && stata(); }
	else return true;
}
bool alb()
{
	if(ptr == s.size()) return true;
	if(s[ptr] == "and") { ptr++; return actor() && alb(); }
	else return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -