京东测开第一题求指教
import java.util.Scanner;public class Main { public static void main(String arghs[]){ Scanner cc = new Scanner(System.in); String c2 = null; while (cc.hasNext()){ String c = cc.nextLine(); int j = 0; for(int i=c.length()-1;i>=0;i--){ if(c.charAt(i)=='0'){ c2 = c.substring(i+1,c.length()); j = i; break; } } c = c2+c.substring(0,j+1); int max = 1; int sum = 1; for(int i=0;i<c.length()-2;i++){ if(c.charAt(i)=='1'&&c.charAt(i+1)=='1'){ sum++; }else{ if(sum>max){ max = sum; } sum =1; i++; } } if(sum>max){ max = sum; } System.out.println(max); } } }
大概思路就是从后面找到第一个0,把0之后的直接接到开头,再遍历找到最大的1,a了百分之64.顺便求一个第二题塔的思路
#京东##笔试题目##春招#