A. Grammar Lessons
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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 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.

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 test(s)
input
petr
output
YES
input
etis atis animatis etis atis amatis
output
NO
input
nataliala kataliala vetra feinites
output
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;
}

Codeforces 113A-Grammar Lessons(实现)的更多相关文章

  1. Codeforces 915E Physical Education Lessons

    原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...

  2. Codeforces 915 E Physical Education Lessons

    题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...

  3. Physical Education Lessons CodeForces - 915E (动态开点线段树)

    Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...

  4. codeforces 45C C. Dancing Lessons STL

    C. Dancing Lessons   There are n people taking dancing lessons. Every person is characterized by his ...

  5. codeforces 893F - Physical Education Lessons 动态开点线段树合并

    https://codeforces.com/contest/893/problem/F 题意: 给一个有根树, 多次查询,每次查询对于$x$i点的子树中,距离$x$小于等于$k$的所有点中权值最小的 ...

  6. 【CodeForces】915 E. Physical Education Lessons 线段树

    [题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...

  7. Physical Education Lessons Codeforces - 915E

    http://codeforces.com/problemset/problem/915/E 大概有几种思路: 1.动态开点线段树+标记下传 #1.1标记永久化:想了一会没想出来 1.2可以先扫一遍询 ...

  8. Codeforces 915E. Physical Education Lessons(动态开点线段树)

    E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...

  9. Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons

    提供两种思路 一种线段树区间更新 另一种用map维护连续的区间,也是题解的思路 第二种很难写(我太渣,看了别人的代码,发现自己写的太烦了) #include<iostream> #incl ...

随机推荐

  1. http协议和web本质(转)

    当你在浏览器地址栏敲入“http://www.cnblogs.com/”,然后猛按回车,呈现在你面前的,将是博客园的首页了(这真是废话,你会认为这是理所当然的).作为一个开发者,尤其是web开发人员, ...

  2. int a[5]={1,2,3,4,5};printf(&quot;%d\n&quot;, *((int*)(&amp;a+1)-2);

    有说服力的笔试题有一定的期限,问:什么是结果,答案是4,为什么要挤? 我明白(不知道是不正确): &a这是一个数组指针,类型int[5],然后&a添加1其实a+sizeof(int)* ...

  3. iOS如何添加照片模拟器(附带诉讼)

    刚開始做图片选择时,使用了最笨的办法给iphone模拟器添加照片. 方法一:首先打开safari.然后找到图片.点击图片,保存到本地(iphone): 方法二:拖动本地计算机的随意一张照片到iphon ...

  4. 使用Canvas和Paint自己绘制折线图

    主要用于Canvas一个特别简单的小demo. 能够手动点击看每一个月份的数据.很easy.就是用paint在canvas上画出来的. 主要内容就是计算左边价格的位置,以下日期的位置,三根虚线的位置, ...

  5. iOS开发无第三方控件的援助达到的效果侧边栏

    最近的研究iOS程序侧边栏.渐渐的发现iOS该方案还开始采取风侧边栏格该,QQ,今日头条,Path(Path运营商最早的侧边栏app该,效果说成是Path效果),所以就研究了下. 然后发现Git Hu ...

  6. BZOJ 1901 Zju 2112 Dynamic Rankings 与更改的树董事长

    标题效果:给定一个序列,单点变化,询价区间k大. 思维:假设没有变化.然后划分树就可以解决,但树的分工仍然是一棵树,它不支持的变化. 主席舒变化实际上是在外带fenwick右护套层值段树,但正确的值线 ...

  7. spring 整合quartz的方式——简单介绍

    一.继承QuartzJobBean,重写executeInternal方法 <bean name="statQuartzJob" class="org.spring ...

  8. cocos2d-x由Jni实现Java与C++打电话给对方

    cocos2d-x由Jni实现Java与C++打电话给对方. cocos2d-x与开发商提供一个类JniHelper,提供java与c++之间的互jni解. 笔者所开发的"史上最坑爹的游戏& ...

  9. Java NIO系列教程(三) Buffer(转)

    Java NIO中的Buffer用于和NIO通道进行交互.如你所知,数据是从通道读入缓冲区,从缓冲区写入到通道中的. 缓冲区本质上是一块可以写入数据,然后可以从中读取数据的内存.这块内存被包装成NIO ...

  10. 使用javascript实现html文字不可选

    如何使用js让html该文本是不可选定它?首先想到的是用css选择实现,如下面: -webkit-touch-callout: none; -webkit-user-select: none; -kh ...