首页 > 试题广场 >

Text Diff

[编程题]Text Diff
  • 热度指数:5 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 128M,其他语言256M
  • 算法知识视频讲解
Alice made some changes to a text file and she wants to know which lines are changed and compare the before and after line contents. Can you help her with this?

输入描述:
The first line contains two integers m (1  m  1000) and n (1  n  1000) – the number of lines in the original text and in the modified text separately. The following m lines are the original text and the next n lines compose the modified text. The length of each text line is in the range [0, 100]. Note that m may not be equal to n.


输出描述:
The result of the comparison is based on original text. If one line is not modified, just output the line with one leading space ‘ ‘.  If this line is modified, output two lines: the original line leading with a ‘-‘ and the modified line leading with a ‘+’.
示例1

输入

3 4
a
bb
ccc
aa
bb
ccc
dddd

输出

-a
+aa
 bb
 ccc
+dddd
示例2

输入

3 3
a
b
c
xx
yy
c

输出

-a
-b
+xx
+yy
 c

备注:
Note that you should use the original text (2~m+1 lines) as base. Also, output the deleted lines first before added ones. E.g. for input [“a”, ”b”, “c”] and [“a”, “c”, “b”], the output should be [“ a”, “-b”, “ c”, “+b”] instead of [“ a”, “+c”, “ b”, “-c”].

这道题你会答吗?花几分钟告诉大家答案吧!