Codeforces 443 B. Kolya and Tandem Repeat
纯粹练JAVA....
import java.util.*; public class Main { public static void main(String[] args) { Scanner cin=new Scanner(System.in); String str=cin.next(); int k=cin.nextInt(); int ans=2; while(k-->0) { str=str+"*"; for(int len=ans/2;2*len<=str.length();len++) { for(int i=0;i+2*len-1<str.length();i++) { boolean flag=true; int u=i,v=i+len; for(int j=0;j<len&&flag;j++) { if(str.charAt(u+j)=='*'||str.charAt(v+j)=='*') continue; if(str.charAt(u+j)==str.charAt(v+j)) continue; else flag=false; } if(flag) ans=Math.max(ans,len*2); } } } System.out.println(ans); } }
版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss