5 seconds
256 megabytes
standard input
standard output
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.
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
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.
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).
petr
YES
etis atis animatis etis atis amatis
NO
nataliala kataliala vetra feinites
YES
应该是Div 1.有点麻烦。最初题意还看错了sad 7次才过掉。
题意: 如今有3种词,形容词,名词,动词,每种词有两种词性,每种词性相应一种后缀,如今给出一个句子的定义:要求是有一个合法单词或一个合法声明。
合法单词是指有一种上面的后缀;合法声明定义为:含有0个以上的形容词+一个名词+0个以上的动词(按形容词名词动词的顺序且所以的词的词性同样)
哎个推断条件就是了。。非常easy漏点
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int INF = 0x3f3f3f3f;
#define LL long long
char s[100010];
char word[100010];
int num[100010];
int change()
{
int len=strlen(word);
if(len<3)
return 0;
if(strcmp(word+len-4,"lios")==0)
return 1;
if(strcmp(word+len-5,"liala")==0)
return -1;
if(strcmp(word+len-3,"etr")==0)
return 2;
if(strcmp(word+len-4,"etra")==0)
return -2;
if(strcmp(word+len-6,"initis")==0)
return 3;
if(strcmp(word+len-6,"inites")==0)
return -3;
return 0; }
int main()
{
while(gets(s))
{
int tp=0,flag=1,i,len=strlen(s),t,p=0,cnt=0;
for(i=0;i<=len;i++)
{
if(s[i]!=' '&&s[i]!='\0')
{
word[p++]=s[i];
}
else
{
word[p]='\0';
t=change();
cnt++;
if(t!=0)
num[tp++]=t;
else
{
flag=0;
break;
}
}
}
//printf("%d\n",cnt);
if(cnt==1&&flag==1)
{
puts("YES");
continue;
}
if(flag==0)
{
puts("NO");
continue;
}
cnt=0;
for(i=0;i<tp;i++)
if(abs(num[i])==2)
cnt++;
if(cnt!=1)
{
puts("NO");
continue;
}
flag=1;
if(num[0]<0)
{
for(i=1;i<tp;i++)
if(num[i]>0)
{
flag=0;
break;
}
}
else
{
for(i=1;i<tp;i++)
if(num[i]<0)
{
flag=0;
break;
}
}
if(flag==0)
{
puts("NO");
continue;
}
flag=1;
for(i=1;i<tp;i++)
{
if(abs(num[i])<abs(num[i-1]))
{
flag=0;
break;
}
}
if(flag)
puts("YES");
else
puts("NO");
}
return 0;
}