QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 256 MB مجموع النقاط: 100

#252. 密码

الإحصائيات

你需要分析消息以寻找各种威胁;然而,这些消息已被加密。幸运的是,它们仅使用凯撒密码加密,这意味着明文中的每个字母都在字母表中向后移动了固定的位数。字母表是循环的,即 z 之后是 a,Z 之后是 A。例如,消息 "How are you?" 在偏移量为 5 时会变成 "Mtb fwj dtz?"。要解密消息,只需将字母向相反方向移动即可。

对于每条消息,你需要确定密钥(偏移量)以及与给定密文对应的明文。为了辅助你,你将获得已知威胁词列表和已知非威胁词列表。与这些列表中的单词匹配时不区分大小写,例如 "word" 可以匹配 "Word"。如果某个密钥产生的已知单词(威胁词和非威胁词)数量多于其他任何密钥,则可以假设你猜对了密钥。在本任务中,单词被定义为由 $1 \leq x\leq 20$ 个 A-Z 和/或 a-z 字符组成的连续序列。所有其他字符不受偏移影响,在明文和密文中保持不变。所有消息(明文和密文)仅由可打印字符组成,包括空格。

输入格式

输入的第一行包含测试用例的数量 $C$ ($1 \leq C \leq 50$)。每个测试用例以一行开始,包含已知非威胁词的数量 $G$ ($1 \leq G \leq 50$)。接下来的 $G$ 行每行包含一个由小写字母组成的非威胁词。下一行包含已知威胁词的数量 $B$ ($1 \leq B \leq 50$)。接下来的 $B$ 行每行包含一个由小写字母组成的威胁词。下一行包含一条长度为 $1 \leq y \leq 1\,000$ 个字符的密文消息。任何行均不包含前导或尾随空格。

输出格式

每个测试用例产生一行或两行输出。

如果可以确定密钥和明文,则第一行输出应包含明文消息,保留原始密文的大小写和标点符号;第二行应包含 "Shift: S, Match: M%, Threat: T%",其中 $S$ ($0 \leq S < 26$) 是加密消息时明文移动的字符数,$M$ 是一个整数,表示明文中已知单词(威胁词和非威胁词)所占的百分比,$T$ 是一个整数,表示明文中威胁词所占的百分比。所有百分比应四舍五入到最接近的 $1\%$。

如果无法确定密钥和明文,则输出一行 "Unable to decipher"。

样例

样例输入 1

2
11
a
also
from
if
it
keep
must
to
want
you
yourself
2
hide
secret
Vs lbh jnag gb xrrc n frperg, lbh zhfg nyfb uvqr vg sebz lbhefrys.
12
a
brother
darkness
destruction
is
it
language
mind
of
the
thing
words
3
beautiful
freedom
truth
Hs'r z adztshetk sghmf, sgd cdrsqtbshnm ne vnqcr.

样例输出 1

If you want to keep a secret, you must also hide it from yourself.
Shift: 13, Match: 100%, Threat: 14%
It's a beautiful thing, the destruction of words.
Shift: 25, Match: 89%, Threat: 11%

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.