QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#10815. 春联

Statistiques

2022 年春节即将来临。Vingying 难掩兴奋之情,开始准备春联。

春联是一对遵循特定规则的诗句。它们常见于华人社区的门框上,作为春节庆祝活动的一部分。春联的内容通常较为传统,蕴含着对繁荣昌盛的期盼。

春联需要满足多种规则。例如,两行诗句的字数必须相同,且两行诗句的含义必须相关等。在这里,我们仅关注声调规则。

众所周知,汉字有四个基本声调:阴平($\bar{a}$)、阳平($\acute{a}$)、上声($\check{a}$)和去声($\grave{a}$)。这些声调可以归纳为两种声调模式:平声和仄声。具体来说,阴平和阳平属于平声,上声和去声属于仄声。

一副春联必须遵循以下声调规则:

  • 两行诗句的声调模式必须相反。这意味着如果一行中的某个字是平声,那么另一行对应位置的字必须是仄声,反之亦然。
  • 第一行的最后一个字必须是仄声,这强制要求第二行的最后一个字必须是平声。

由于 Vingying 创意十足,他瞬间创作了 $T$ 副春联。他想知道每一副春联是否都符合上述声调规则。

输入格式

第一行包含一个整数 $T$ ($1 \le T \le 100$),表示春联的数量。

对于每一副春联,第一行包含一个整数 $n$ ($1 \le n \le 20$),表示每行诗句的汉字数量。

接下来的两行,每行包含 $n$ 个字符串,每个字符串代表一个汉字。每个字符串由小写字母组成(表示汉字的拼音),后跟一个数字 $1$(平声)、$2$(阳平)、$3$(上声)或 $4$(去声)来表示声调。

保证每个字符串的长度不小于 $2$ 且不超过 $7$。

输出格式

对于每一副春联,如果它符合声调规则,则输出 YES;否则,输出 NO。每行输出一个结果。

样例

输入 1

4
7
qian1 men2 wan3 hu3 tong2 tong2 ri4
zong3 ba3 xin1 tao2 huan4 jiu4 fu2
7
ping2 ping2 ze4 ze4 ping2 ping2 ze4
ze4 ze4 ping2 ping2 ze4 ze4 ping2
7
gou3 li4 guo2 jia1 sheng1 si3 yi3
qi3 yin1 huo4 fu2 bi4 qu1 zhi1
3
nun1 heh1 heh1
a4 a4 a4

输出 1

YES
YES
NO
NO

说明

对于第三个样例,第一个字的声调不符合规则,因为它们都是仄声。

对于第四个样例,最后一个字的声调不符合规则,因为第一行的最后一个字不是仄声。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.