a046: Longest Common Substring 最長共同子串列
標籤 : 迴圈
通過比率 : 100% (10 人 / 10 人 ) (非即時)
評分方式 :
Tolerant

最近更新 : 2019-04-09 08:54

內容

 

Design a program to find the longest common substring of two strings. A substring is a consecutive segment of a string. For instance, "agggcte" is a substring of "ggtttagggctehhdh" but "gthh" is not. For two strings A and B, a string C is a common substring of A and B if C is a substring of both A and B. Two strings may have many common substrings, and you need to find the longest one. For example,

(設計一支可以找出兩個字串中最長相同子字串的程式。所謂子字串是一個字串中任一長度的連續的字元組合。例如:"agggcte"是"ggtttagggctehhdh"的子字串,但 "gthh" 不是。對兩個字串A與B而言,如果C字串同時為A與B的子字串,則C為A與B的共同字串。兩個字串可能有很多的共同子字串,你要把其中最長的子字串找出來。

A ="gggttttagggctehhdh"

B ="ttwhwttthhsagggcte"

The longest common substring is "agggcte". (最長子字串為"agggcte" )

 

 

輸入說明

        The input contains five test cases and each case has two lines, each for one string. A string consists of alphanumeric characters and the length is at most 200.

輸入包含5組測試資料,每組測試資料有二列字串。一個字串由英文字母與數字組成,字串最長為200。

輸出說明

Output the length of the longest common substring of each case in one line. Please add a “newline” in the end of the output.

輸出每組測試資料之最長相同子字串的長度,輸出下一組測試資料結果前應換行。

範例輸入
gggttttagggctehhdh
ttwhwttthhsagggcte
abcdefg11234
113cdefgrrr
a
ab
a1
1a
ab
xyz
範例輸出
7
5
1
1
0
測資資訊 :
記憶體限制 : 64 MB
隱藏 測資點#0 (33%): 2.0s , <1K
隱藏 測資點#1 (33%): 2.0s , <1K
隱藏 測資點#2 (34%): 2.0s , <1K
提示 :
標籤:
迴圈
出處:
ITSA_50th [編輯 :
shengZJ (shengZJ)
]


編號 身分 題目 主題 人氣 發表日期
沒有發現任何「解題報告」