-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC443B.java
More file actions
58 lines (45 loc) · 1.14 KB
/
Copy pathC443B.java
File metadata and controls
58 lines (45 loc) · 1.14 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
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class C443B {
public static char p='.';
/***/
public static void main(String[] args) {
BufferedReader reader =new BufferedReader(new InputStreamReader(System.in));
try{
String s=reader.readLine().trim();
int k=Integer.valueOf(reader.readLine().trim());
for(int i=0;i!=k;i++)
s+=String.valueOf(p);
int r=(s.length()/2);
boolean isTandem=false;
while(!isTandem &&(r>0)){
int len=r*2;
// System.err.println("Len "+len);
int u=0;
while(!isTandem&&(u<=(s.length()-len))){
String sub=s.substring(u,u+len);
// System.err.println("Test "+sub);
isTandem=isTandem(sub);
u++;
}
if(!isTandem)
r--;
}
System.out.println(r*2);
reader.close();
}catch(Exception e){}
}
public static boolean isTandem(String s){
char[] chars=s.toCharArray();
int r=chars.length/2;
if((chars.length%2)!=0)
return false;
int i=0;
boolean isSame=true;
while(isSame&&(i<r)){
isSame=(chars[i]==chars[i+r])||(chars[i]==p)||(chars[i+r]==p);
i++;
}
return isSame;
}
}