编程介的小学生 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 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?