若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1149: Intellectual Property

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,249

题目描述

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.
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.
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.

输入

暂无

输出

暂无

样例输入

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

样例输出

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

参考代码

#include <stdlib.h>
#include <stdio.h>
char n[5000], m[5000];
int i,j,k,nn,mn;
int rem(int d) 
{
    int i,carry=0;
    for (i=0;i<nn;i++) 
    {
        carry = 10 * carry + n[i];
        carry %= d;
    }
    return carry;
}
void Div(int d) 
{
    int i,carry=0;
    for (i=0;i<nn;i++) 
    {
        carry = 10 * carry + n[i];
        n[i] = carry/d;
        carry %= d;
    }
}
int one() 
{
    int i;
    for (i=0;i+1<nn;i++) if (n[i]) return 0;
    return n[i] == 1;
}
main() 
{
    while (strcmp(gets(n),"-1")) 
    {
        nn = strlen(n);
        if (nn == 1) 
        {
            printf("1%cn",n[0]);
         continue;
      }
      mn = 0;
      for (i=0;i<nn;i++) n[i] -= '0';
      for (i=9;i>1;i--) {
         while (rem(i) == 0) {
            m[mn++] = '0'+i;
            Div(i);
         }
      }
      if (!one()) {
         printf("There is no such number.n");
         continue;
      }
      for (i=mn-1;i>=0;i--) printf("%c",m[i]);
      printf("n");
   }
}

解析

暂无

hustoj

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 原站点 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist