📄 e.cpp
字号:
#include <fstream>#include <iostream>#include <strstream>#include <string.h>using namespace std;ifstream fin("e.in");const char* article[2] = {"a", "the"};const char* noun[8] = {"tom", "jerry", "goofy", "mickey", "jimmy", "dog", "cat", "mouse"};const char* verb[4] = {"hate", "love", "know", "like"};const int MAX = 1000+5;int n;char list[MAX][MAX];int isarticle(int);int isnoun(int);int isverb(int);int isactor(int, int);int isactivelist(int, int);int isaction(int, int);int isstatement(int, int);char line[1000000], temp[1000000];main() { int T; fin >> T; for (fin.getline(line, 1000000); T--;) { fin.getline(line, 1000000); temp[0] = '\0'; int i; for (i = 0; line[i]; i++) { if (line[i] == ',') strcat(temp, " "); temp[strlen(temp) + 1] = '\0'; temp[strlen(temp)] = line[i]; if (line[i] == ',') strcat(temp, " "); } istrstream is(temp); for (n = 0; is >> list[n]; n++); if (isstatement(0, n - 1)) cout << "YES I WILL" << endl; else cout << "NO I WON'T" << endl; } return 0;}int isarticle(int id) { int i; for (i = 0; i < 2; i++) if (strcmp(list[id], article[i]) == 0) return 1; return 0;}int isnoun(int id) { int i; for (i = 0; i < 8; i++) if (strcmp(list[id], noun[i]) == 0) return 1; return 0;}int isverb(int id) { char temp[MAX]; strcpy(temp, list[id]); while (temp[strlen(temp) - 1] == 's') temp[strlen(temp) - 1] = '\0'; int i; for (i = 0; i < 4; i++) if (strcmp(temp, verb[i]) == 0) return 1; return 0;}int isactor(int l, int r) { return l == r && isnoun(l) || l + 1 == r && isarticle(l) && isnoun(r);}int isactivelist(int l, int r) { int i, last = l; for (i = l; i <= r; i++) if (strcmp(list[i], "and") == 0) if (!isactor(last, i - 1)) return 0; else last = i + 1; return isactor(last, r);}int isaction(int l, int r) { int i; for (i = l; i <= r; i++) if (isverb(i)) break; return isactivelist(l, i - 1) && isactivelist(i + 1, r);}int isstatement(int l, int r) { int i, last = l; for (i = l; i <= r; i++) if (strcmp(list[i], ",") == 0) if (!isaction(last, i - 1)) return 0; else last = i + 1; return isaction(last, r);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -