Problem6227--USACO 2021 February Contest, Bronze —— Problem 1: Year of the Cow

6227: USACO 2021 February Contest, Bronze —— Problem 1: Year of the Cow

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

Farmer John's cows are excited to learn that Chinese New Year was recently celebrated, ushering in the year of the Ox, always a bovine favorite. As we know, the zodiac animals for Chinese calendar years follow a $12$-year cycle: Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, Rat, and then Ox again.
Bessie the cow is proud to say she was born in a year of the Ox, many years ago. Her friend Elsie wants to know how many years apart from Bessie she was born, and hopes you can help her deduce this by looking at relationships between the birth years of several cows on the farm.
Farmer John 的奶牛们得知最近正在庆祝牛年的到来时十分兴奋。牛年总是奶牛们的最爱。
我们知道,中国历法中每一年所对应的生肖遵循 $12$ 年的周期:Ox, Tiger, Rabbit, Dragon, Snake, Horse, Goat, Monkey, Rooster, Dog, Pig, Rat(牛、虎、兔、龙、蛇、马、羊、猴、鸡、狗、猪、鼠),然后回到牛。
奶牛 Bessie 自豪地说她是在许多年前的一个牛年出生的。她的朋友 Elsie 想要知道她与 Bessie 出生相差多少年,并且希望你能够通过查看农场上若干奶牛出生年份之间的关系来帮助她推算。

Input

The first line of input contains an integer $N\ (1≤N≤100)$. Each of the next $N$ lines contains an $8$-word phrase specifying the relationship between the birth years of two cows. It is of the form "Mildred born in previous Dragon year from Bessie",
or
"Mildred born in next Dragon year from Bessie"
The last word is the name of a cow on the farm, which is either "Bessie" or a cow that has already been mentioned in a previous line of input.
The first word is the name of a cow on the farm who is not "Bessie" and who has not yet been mentioned in the input. All cow names have at most $10$ characters that are in the range a..z or A..Z.
The $5$th word is one of the $12$ zodiac animals above.
The $4$th word is either "previous" or "next". For example, if the phrase is "Mildred born in previous Dragon year from Bessie", then Mildred's year of birth was the Dragon year closest to and strictly before (not equal to) Bessie's birth year.
输入的第一行包含一个整数 $N$。以下 $N$ 行每行包含一个 $8$ 个单词的短语,指定了两头奶牛的出生年份之间的关系,格式为
"Mildred born in previous Dragon year from Bessie"(Mildred 在 Bessie 出生的前一个龙年出生),

"Mildred born in next Dragon year from Bessie"(Mildred 在 Bessie 出生的后一个龙年出生)。
最后一个单词是农场上某一头奶牛的名字,为 "Bessie" 或一头已经在之前的输入中出现过的奶牛。
第一个单词是农场上某一头奶牛的名字,不为 "Bessie" 且未在之前的输入中出现过。所有的奶牛名字不超过 $10$ 个字符,且仅包含字符 a..z 或 A..Z。
第 $5$ 个单词是上述十二生肖之一。
第 $4$ 个单词是 "previous"(之前)或 "next"(之后)之一。例如,如果短语为 "Mildred born in previous Dragon year from Bessie",则 Mildred 的出生年份为最为接近且严格处于 Bessie 的出生年份之前(不等于)的龙年。

Output

Please output the number of years by which Bessie and Elsie's birth years differ. It is guaranteed that this number can be determined by the input given.
输出 Bessie 和 Elsie 的出生年份之间相差的年数。输入保证可以通过给定的信息求出结果。

Sample 1 Input

4
Mildred born in previous Dragon year from Bessie
Gretta born in previous Monkey year from Mildred
Elsie born in next Ox year from Gretta
Paulina born in next Dog year from Bessie

Sample 1 Output

12
In the input above,
  • Elsie was born $12$ years before Bessie.
  • Mildred was born $9$ years before Bessie.
  • Gretta was born $17$ years before Bessie.
  • Paulina was born $9$ years after Bessie.

HINT

USACO 2021 February Contest, Bronze

EDITORIAL

Source/Category