forked from damaohongtu/JavaInterview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopee_03.java
More file actions
59 lines (42 loc) · 1.05 KB
/
Shopee_03.java
File metadata and controls
59 lines (42 loc) · 1.05 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
50
51
52
53
54
55
56
57
58
59
package BiShi;
import java.util.Scanner;
/**
* @Classname Shopee_03
* @Description TODO
* @Date 19-7-27 下午6:53
* @Created by mao<[email protected]>
*/
public class Shopee_03 {
public static boolean divide(String s,String d){
String tmp=d;
String dd=d;
int len=dd.length();
while (len<=s.length()){
if(s.equals(dd)){
return true;
}
dd=dd+tmp;
len=dd.length();
}
return false;
}
public static String common(String s1,String s2){
String res="";
for(int i=0;i<s1.length();i++){
String d=s1.substring(0,i+1);
if(divide(s1,d)&÷(s2,d)){
res=d;
}
}
return res;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while (sc.hasNext()){
String s1=sc.next();
String s2=sc.next();
String res=common(s1,s2);
System.out.println(res);
}
}
}