题解 | #密码截取#

密码截取

http://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1

import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.List;

public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()) { String s = sc.nextLine(); char[] test = s.toCharArray(); // Create a new array to store all the symmetric password length ArrayList as = new ArrayList(); a:for(int i = 0; i < test.length; i++) { b:for(int j = test.length - 1; j >= i; j--) { if(test[i] == test[j]) { //Consider there is only three elements in String if( j - i == 2) { as.add(3); // If the array length is 1 } else if(j == i && test.length == 1) { as.add(1); } else if(j - i > 2) { int ck = (j-i)/2, cka = 0; for(int k = 1; k <= (j-i)/2; k++) { if(test[i+k] == test[j-k]) { cka++; } } if(ck == cka) { as.add(j - i + 1); } } } } } int max = 0; //Compare the length, find the max for(int l = 0; l < as.size(); l++) { if(max < as.get(l)) { max = as.get(l); } } System.out.println(max); } } }

全部评论

相关推荐

09-17 19:25
已编辑
太原理工大学 游戏测试
叁六玖:公司名发我,我要这个HR带我打瓦
我的秋招日记
点赞 评论 收藏
分享
09-14 20:51
四川大学 Java
慢热的鲸鱼在学习:985加粗就行了,第二个项目来不及准备也没事,省的写了问你你还不会。你只需准备面试八股和项目场景,剩下的交给985。即使面不过也没事,面试经验是最重要的,你现在不缺时间
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务