Description
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb.
- There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine.
- Masculine adjectives end with -lios, and feminine adjectives end with-liala.
- Masculine nouns end with -etr, and feminime nouns end with-etra.
- Masculine verbs end with -initis, and feminime verbs end with-inites.
- Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language.
- It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language.
- There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications.
- A sentence is either exactly one valid language word or exactly one statement.
Statement is any sequence of the Petya's language, that satisfy both conditions:
- Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs.
- All words in the statement should have the same gender.
After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
Input
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
Output
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
Sample Input
petr
YES
etis atis animatis etis atis amatis
NO
nataliala kataliala vetra feinites
YES
***********************************************************************************
题意:就是一组自创的字符串中 有动词,名词,形容词。
并且这些词还有性别之分,一组字符串中必须有一个名词,然后形容词和动词的个数>=0.
且必须按形容词+名词+动词的顺序,当这组字符串只有一个词时,只要保证这个词的后缀中含 {lios","liala","etr","etra","initis","inites"} 其中一个也输出YES。
***********************************************************************************
#include<cstdio>
#include<cstring>
using namespace std;
char s[100005];
char c[6][20]={"lios","liala","etr","etra","initis","inites"};
char n[6]={4,5,3,4,6,6};
int main()
{
bool flag=true;
int noun=0,num=0;
int last=-1;//存上一个单词的出现的位置
while(scanf("%s",s)!=EOF)
{
if(flag)
{
num++;
int t=-1;
int i;
int len=strlen(s);
for(i=0;i<6;i++)
if(len>=n[i] && strcmp(c[i],s+len-n[i])==0)//len>=n[i]保证这一个单词中的字母个数最起码为对应后缀单词的长度,求当前单词在 { <span style="font-family: Arial, Helvetica, sans-serif;"> //数组中的位置,用t记录下标</span>
t=i;
break;
}
if(t==2 || t==3) noun++;
if(t==-1 || (last>=0 && t%2!=last%2)||t<last)// 这个的意思(last>=0 && t%2!=last%2) 是保证字符串中的单词词性相同
{ // last>=0表示符合要求的单词存在过,而如果t< last,则表示单词出现的顺序不
flag=false; // 符合要求,这个if语句里的条件比较巧妙。
continue;
}
last=t;//记录单词出现的位置
}
}
if(flag && (num==1 || noun==1))//如果当flag=1,num==1时也应输出YES,此时只有一个名词,并且符合要求。
puts("YES");
else
puts("NO");
return 0;
}
比赛的时候没写出来,编译错误。之后又想了想,发现自己的写法太麻烦了,然后搜了一下解题报告,看到别人的解法,我也是醉了~~~~=。=
上面贴了一份自己可以看懂的代码\\\\\\\\\\\\\(又看了一次,太巧妙了)
也把代码来源写下:传送门