ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1297. Palindrome

I am getting WA at #1
Posted by Atindra Das 26 Apr 2013 01:44
I have tested for almost all test cases intentioned in discussions.
what might be the problem ?? ple help
code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package timusonlinejudge;

import java.util.Scanner;

/**
*
* @author dell
*/
public class N1297 {
public String getPal(String s, int i, int j,String result){
while((i>=0)&&(j<=s.length()-1)){
if((""+s.charAt(i)).equalsIgnoreCase(""+s.charAt(j))){
result = s.charAt(i)+result+s.charAt(j);
i--;j++;
}
else{
break;
}
}
return result;
}
public String longestPal(String s){
// System.out.println("---");
if(s.isEmpty()){
return "";
}
String result = s.substring(0,1);

//System.out.println("---"+result);
for(int i = 1; i<s.length();i++){
if((""+s.charAt(i-1)).equalsIgnoreCase(""+s.charAt(i))){
String temp = getPal(s,i-1,i,"");
//System.out.println(temp);
if(temp.length()>result.length()){
result = new String(temp);
//System.out.println(temp);
}
}

String temp = getPal(s,i-1,i+1,""+s.charAt(i));
//System.out.println(temp);
if(temp.length()>result.length()){
result = new String(temp);
//System.out.println(temp);
}

}
return result;
}
public static void main(String[] args) {
N1297 main = new N1297();
Scanner sc = new Scanner(System.in);

String input = sc.nextLine();
//System.out.println(input);
System.out.println(main.longestPal(input));

// TODO code application logic here
}

}