-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1237CompareSubstring.java
More file actions
49 lines (44 loc) · 1.4 KB
/
URI1237CompareSubstring.java
File metadata and controls
49 lines (44 loc) · 1.4 KB
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1237">Compare
* Substring</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1237CompareSubstring {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String s1, s2, max, min;
while ((s1 = in.readLine()) != null) {
s2 = in.readLine();
if (s1.length() >= s2.length()) {
max = s1;
min = s2;
} else {
max = s2;
min = s1;
}
int minLength = min.length();
int maxS = minLength;
boolean f = true;
while (maxS > 0 && f) {
int diff = minLength - maxS;
for (int i = 0; i <= diff; i++) {
if (max.contains(min.substring(i, i + maxS))) {
f = false;
maxS++;
break;
}
}
maxS--;
}
System.out.println(maxS);
}
out.close();
}
}