-
Notifications
You must be signed in to change notification settings - Fork 2
/
long1.cpp
executable file
·54 lines (44 loc) · 1.05 KB
/
long1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* =====================================================================================
*
* Filename: long.cpp
*
* Description: POJ 2774. Long Long Message
*
* Version: 1.0
* Created: 07/12/2009 03:02:21 PM
* Revision: none
* Compiler: gcc
*
* Author: Ming Chen (chm), mingchen@cse.buaa.edu.cn
* Company: BUAA.edu
*
* =====================================================================================
*/
#include <iostream>
using namespace std;
const int MAXN = 100001;
int main()
{
char stra[MAXN], strb[MAXN];
int mlen, t, lena, lenb;
short lens[MAXN] = {0};
cin.getline(stra, MAXN);
cin.getline(strb, MAXN);
for (lena=0; stra[lena] != '\0'; ++lena) ;
for (lenb=0; strb[lenb] != '\0'; ++lenb) ;
mlen = 0;
for (int i=1; i<=lena; ++i) {
for (int j=lenb; j>0; --j) {
if ( stra[i-1] == strb[j-1] ) {
t = lens[j-1] + 1;
if ( t > mlen ) mlen = t;
} else {
t = 0;
}
lens[j] = t;
}
}
cout << mlen << endl;
return 0;
}