QOJ.ac

QOJ

時間限制: 30.0 s 記憶體限制: 256 MB 總分: 100

#17333. 时髦

统计

Stylish 是一种编程语言,其语法由名称(拉丁字母序列)、三种分组符号、英文句点(‘.’)和换行符组成。分组符号包括圆括号(‘(’ 和 ‘)’)、花括号(‘{’ 和 ‘}’)以及方括号(‘[’ 和 ‘]’),它们必须正确匹配并嵌套。与大多数其他编程语言不同,Stylish 使用句点而不是空格来分隔词项。以下是一个 Stylish 程序的示例。

1 (Welcome.to
2 .........Stylish)
3 {Stylish.is
4 .....[.(a.programming.language.fun.to.learn)
5 .......]
6 ..... Maybe.[
7 .......It.will.be.an.official.ICPC.language
8 .......]
9 .....}

如示例所示,Stylish 程序使用句点进行缩进。一行的缩进量即为该行开头句点的数量。

你的任务是拜访 Stylish 大师,学习他们的缩进风格,并成为最年轻的 Stylish 大师。一个排版良好的 Stylish 程序的缩进风格由一个三元组整数 $(R, C, S)$ 定义,满足 $1 \le R, C, S \le 20$。其中 $R$、$C$ 和 $S$ 分别表示由左圆括号、左花括号和左方括号引入的缩进量。

在排版良好的程序中,某一行的缩进量由公式 $R(r_o - r_c) + C(c_o - c_c) + S(s_o - s_c)$ 给出,其中 $r_o$、$c_o$ 和 $s_o$ 分别是之前所有行中左圆括号、左花括号和左方括号的出现次数,而 $r_c$、$c_c$ 和 $s_c$ 分别是右圆括号、右花括号和右方括号的出现次数。在任何排版良好的程序中,第一行都没有缩进。

上述示例是按照缩进风格 $(R, C, S) = (9, 5, 2)$ 进行排版的。上述程序第一行中出现的唯一分组符号是一个左圆括号。因此,第二行的缩进量为 $9 \cdot (1 - 0) + 5 \cdot (0 - 0) + 2 \cdot (0 - 0) = 9$。前四行包含两个左圆括号、一个左花括号、一个左方括号、两个右圆括号,但没有右花括号和右方括号。因此,第五行的缩进量为 $9 \cdot (2 - 2) + 5 \cdot (1 - 0) + 2 \cdot (1 - 0) = 7$。

Stylish 大师只写排版良好的 Stylish 程序。每位大师都有自己独特的缩进风格。

编写一个程序来模仿 Stylish 大师的缩进风格。

输入格式

输入包含多个数据集。每个数据集的第一行包含两个整数 $p$ ($1 \le p \le 10$) 和 $q$ ($1 \le q \le 10$)。接下来的 $p$ 行构成一个由 Stylish 大师编写的排版良好的程序 $P$,再接下来的 $q$ 行构成另一个程序 $Q$。你可以假设两个程序的每一行都至少包含一个字符,且最多包含 80 个字符。此外,你可以假设 $Q$ 的任何一行都不以句点开头。

最后一个数据集后面紧跟一行,包含两个零。

输出格式

将 $P$ 的缩进风格应用到 $Q$ 上,并输出 $Q$ 中每一行的合适缩进量。这些缩进量必须按 $Q$ 中对应行的顺序输出在同一行中,并用单个空格分隔。最后一个数字后面不应有尾随空格。如果通过分析 $P$ 无法唯一确定 $Q$ 中某一行的合适缩进量,则对该行输出 -1。

样例

输入样例 1

5 4
(Follow.my.style
.........starting.from.round.brackets)
{then.curly.brackets
.....[.and.finally
.......square.brackets.]}
(Thank.you
{for.showing.me
[all
the.secrets]})
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
(I.learned
how.to.use.round.brackets)
4 2
(This.time.I.will.show.you
.........(how.to.use.round.brackets)
.........[but.not.about.square.brackets]
.........{nor.curly.brackets})
[I.have.not.learned
how.to.use.square.brackets]
2 2
(Be.smart.and.let.fear.of
..(closed.brackets).go)
(A.pair.of.round.brackets.enclosing
[A.line.enclosed.in.square.brackets])
1 2
Telling.you.nothing.but.you.can.make.it
[One.liner.(is).(never.indented)]
[One.liner.(is).(never.indented)]
2 4
([{Learn.from.my.KungFu
...}])
((
{{
[[
]]}}))
1 2
Do.not.waste.your.time.trying.to.read.from.emptiness
(
)
2 3
({Quite.interesting.art.of.ambiguity
....})
{
(
)}
2 4
({[
............................................................]})
(
{
[
]})
0 0

输出样例 1

0 9 14 16
0 9
0 -1
0 2
0 0
0 2 4 6
0 -1
0 -1 4
0 20 40 60

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.