程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces 113A-Grammar Lessons(實現)

Codeforces 113A-Grammar Lessons(實現)

編輯:C++入門知識

Codeforces 113A-Grammar Lessons(實現)


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個以上的動詞(按形容詞名詞動詞的順序且所以的詞的詞性相同)
      哎個判斷條件就是了。。很容易漏點
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      #include 
      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;i0)
      				{
      					flag=0;
      				    break;
      				}
      		}
      		else
      		{
      			for(i=1;i

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved