题解 | #统计回文#
统计回文
http://www.nowcoder.com/practice/9d1559511b3849deaa71b576fa7009dc
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String s1 = sc.nextLine(); StringBuilder sb1 = new StringBuilder(s1); String s2 = sc.nextLine(); StringBuilder sb2 = new StringBuilder(s2); int res = power(sb1,sb2); System.out.print(res); } static int power(StringBuilder sb1,StringBuilder sb2){ int res=0; for(int i=0;i<=sb1.length();i++){ StringBuilder temp= new StringBuilder(sb1); temp.insert(i,sb2); if(Reverse(temp)){ res++; } } return res; } static boolean Reverse(StringBuilder sb){ int i=0; for(;i<sb.length()/2;i++){ if(sb.charAt(i) == sb.charAt(sb.length()-1-i)){ continue; }else{ break; } } if(i==sb.length()/2){ return true; }else{ return false; } } }