My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 15 attachment: Try2.java (735 bytes)

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
import java.util.Scanner;


public class Try2 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();

for (int i=3;i<=s.length();i++) {
for (int j=0;j<=s.length()-i;j++) {
if (isPol(s.substring(j, j+i))) {
System.out.println(s.substring(j, j+i));
}
}
}
}

// åñòü ëè ïîëèíäðîìîì
static boolean isPol(String s){
byte[] b = s.getBytes();
int mid = b.length/2;
if (b.length%2 == 0){
for (int i=0; i<mid; i++) {
if (b[mid+i]!=b[mid-1-i]) {
return false;
}
}
} else {
for (int i=0; i<mid; i++) {
if (b[mid+1+i]!=b[mid-1-i]) {
return false;
}
}
}
return true;
}

}
Powered by Google Project Hosting