编程介的小学生 2017-04-21 02:53 采纳率: 20.5%
浏览 852
已采纳

Bustered Plaque

James has a problem. He assembled a rectangular plaque from a lot of square tiles, each with a lower-case letter or blank.

The plaque fell down and broke into jagged pieces.

While James was reaching for the glue gun his faithful dog Buster pushed the pieces around.

Fortunately, Buster has not flipped a piece over - after all he was using his nose - but he did manage to rotate a few of the pieces and he has nudged all letters to be upright again. James fears that Buster even buried a piece or two, in which case the plaque would be lost forever.

James needs all the help he can get �� write a program to try and reassemble the plaque.

Input

The first line contains two positive integers w and n, the number of words on the plaque and the number of pieces. The next w lines contain one word each, not necessarily in the right order.

Words consist of lower-case letters. On the plaque, words are separated by single blanks and wrap around. There may be trailing blanks at the bottom right of the plaque.

Finally, for each of the n pieces there is one line with two positive integers r and c, the number of rows and columns for a rectangle which can just contain the piece; this line is followed by r lines with c non-blank characters each, where an underscore represents a blank tile and # represents a tile position which is not part of the piece; all other characters are lower-case.

Output

Your program must print the assembled plaque (with underscores for blanks) or the words "No solution". Print a blank line between two consecutive test cases.

Sample Input

9 8
brown
dog
fox
jumped
lazy
over
quick
the
the
3 4
##p#
##o#
eht
3 4
e###
xo##
ciuq
4 3
#k#
#
#
#r#
do
4 2
_b
ju
_t
#g
3 3
r##
m##
he

3 3
_##
ndl
we#
3 3
#v#
foz
#_a
1 1
y

Sample Output

the_quick_b
rown_fox_ju
mped_over_t
he_lazy_dog

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-05-05 04:17
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计