fork(1) download
  1. //package pkg1297palindrome;
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.  
  8. InputReader in;
  9.  
  10. public static void main(String[] args) {
  11. new Main().Run();
  12. }
  13.  
  14. void Solve() throws Exception{
  15. String s;
  16. s = in.readLine();
  17. int n = s.length();
  18. char[] ss = s.toCharArray();
  19. s = "";
  20. for(int i = 0; i < n; i++) s = s + ss[i] + "0";
  21. int m = s.length();
  22. char[] s2 = s.toCharArray();
  23. int max = 1, M = 1;
  24. for(int i = 1; i < m - 1; i++){
  25. int L = i, R = i;
  26. while(s2[L] == s2[R]){
  27. L--; R++;
  28. if(L < 0 || R >= m) {
  29. L++; R--; break;
  30. }
  31. }
  32. if(max < R - L + 1){
  33. max = R - L + 1;
  34. M = i;
  35. }
  36. }
  37. s = "";
  38. int L = M, R = M;
  39. while(s2[L] == s2[R]){
  40. if(s2[L] != '0') {
  41. if(L != R) s = s2[L] + s + s2[R];
  42. else s = s + s2[L];
  43. }
  44. L--; R++;
  45. if(L < 0 || R >= m) break;
  46. }
  47. out.println(s);
  48. }
  49.  
  50. public void Run(){
  51. try{
  52. File defaultInput = new File("text.inp");
  53. if(defaultInput.exists()) in = new InputReader("text.inp");
  54. else in = new InputReader();
  55. out = new PrintWriter(System.out);
  56. Solve();
  57. out.close();
  58. } catch (Exception e){
  59. e.printStackTrace();
  60. System.exit(261);
  61. }
  62. }
  63.  
  64. class InputReader {
  65. StringTokenizer tokenizer;
  66.  
  67. InputReader() {
  68. reader = new BufferedReader(new InputStreamReader(System.in));
  69. }
  70.  
  71. InputReader(String fileName) throws FileNotFoundException {
  72. reader = new BufferedReader(new FileReader(new File(fileName)));
  73. }
  74.  
  75. String readLine() throws IOException {
  76. return reader.readLine();
  77. }
  78.  
  79. String nextToken() throws IOException {
  80. while (tokenizer == null || !tokenizer.hasMoreTokens())
  81. tokenizer = new StringTokenizer(readLine());
  82. return tokenizer.nextToken();
  83. }
  84.  
  85. boolean hasMoreTokens() throws IOException {
  86. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  87. String s = readLine();
  88. if (s == null) return false;
  89. tokenizer = new StringTokenizer(s);
  90. }
  91. return true;
  92. }
  93.  
  94. int nextInt() throws NumberFormatException, IOException {
  95. return Integer.parseInt(nextToken());
  96. }
  97.  
  98. long nextLong() throws NumberFormatException, IOException {
  99. return Long.parseLong(nextToken());
  100. }
  101.  
  102. double nextDouble() throws NumberFormatException, IOException {
  103. return Double.parseDouble(nextToken());
  104. }
  105. }
  106.  
  107. }
  108.  
Runtime error #stdin #stdout #stderr 0.07s 381184KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
java.lang.NullPointerException
	at Main.Solve(Main.java:18)
	at Main.Run(Main.java:57)
	at Main.main(Main.java:12)