编程介的小学生 2017-08-10 08:52 采纳率: 20.5%
浏览 756
已采纳

Intellectual Property

Description

TDP Inc. has decided to sue JCN Inc. for copyright infringement. To this end, TDP wishes to find infringing segments within JCN's code base, to show to selected media representatives. Since TDP has fired all its technical staff, it is looking to hire a consultant to be paid on a contingency basis should the lawsuit be successful. To demonstrate your qualifications for this position, you are to solve the problem on a number of test cases.
Input

Each test case begins with a positive integer k, the number of infringing segments to be found. Following this line are two code bases. The first code base is preceded by the line "BEGIN TDP CODEBASE" and contains a number of lines followed by the line "END TDP CODEBASE". The second code base is preceded by "BEGIN JCN CODEBASE" and followed by "END JCN CODEBASE". The line "END TDP CODEBASE" does not appear in the first code base and the line "END JCN CODEBASE" does not appear in the second. A line containing 0 follows the last test case.
Output

For each test case you should output: (1) a line containing "CASE n" where n is the number of the test case; (2) up to k infringing segments. Each segment should be printed exactly as it appears in the JCN code base (including newlines and whitespace) and should be preceded by a line containing "INFRINGING SEGMENT m LENGTH l POSITION p" where m is the number of the segment within the test case, l is the length of the segment (in characters) and p is the position of the segment (in characters from the start of the JCN codebase). Output an empty line between test cases.

A code base is simply a string of characters. An infringing segment is a non-empty contiguous sequence of characters in the JCN code base that is textually identical to some contiguous sequence of characters in the TDP code base, and is not contained in a larger infringing segment. You should consider all characters in the code base, including spaces and the newline character at the end of each line.

If there are k or fewer common segments, print them all in decreasing order by length; if several segments have the same length, print them in the order they occur in JCN's code base. If there are more than k segments, print the first k according to the given order.

You may assume that no code base contains more than 50,000 characters.
Sample Input

6
BEGIN TDP CODEBASE
the quick brown fox
jumps over the lazy dog.
so there!
END TDP CODEBASE
BEGIN JCN CODEBASE
now is the time for all
good men to come to the aid
of the party.
so there!
END JCN CODEBASE
100
BEGIN TDP CODEBASE
xyzzy
END TDP CODEBASE
BEGIN JCN CODEBASE
xyzzabczzyy
END JCN CODEBASE
0
Sample Output

CASE 1
INFRINGING SEGMENT 1 LENGTH 12 POSITION 64
.
so there!

INFRINGING SEGMENT 2 LENGTH 5 POSITION 6
the
INFRINGING SEGMENT 3 LENGTH 5 POSITION 42
o the
INFRINGING SEGMENT 4 LENGTH 5 POSITION 43
the
INFRINGING SEGMENT 5 LENGTH 5 POSITION 54
the
INFRINGING SEGMENT 6 LENGTH 3 POSITION 15
fo

CASE 2
INFRINGING SEGMENT 1 LENGTH 4 POSITION 0
xyzz
INFRINGING SEGMENT 2 LENGTH 3 POSITION 7
zzy
INFRINGING SEGMENT 3 LENGTH 2 POSITION 10
y

  • 写回答

1条回答 默认 最新

  • devmiao 2017-08-23 16:36
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题