项链问题 package ojtest; import java.util.Scanner; public class Sohu1 { public static int[] exist; public static boolean valid(){ for(int i=0;i<exist.length;i++) if(exist[i]<=0) return false; return true; } public static void add(char c){ if((c-'A')>=0&&('E'-c)>=0) exist[c-'A']++; } public static void remove(char c){ if((c-'A')>=0&&('E'-c)>=0) exist[c-'A']--; } public static int getmax(String str){ char[] chars=str.toCharArray(); int n=chars.length/2; int s=0,e=0,min=n; for(;e<chars.length;){ if(!valid()) add(chars[e++]); else{ min=Math.min(min, e-s); remove(chars[s++]); } } while(valid()){ min=Math.min(min, e-s); remove(chars[s++]); } return n-min; } public static void main(String[] args) { Scanner input=new Scanner(System.in); String str; while(input.hasNextLine()){ str=input.nextLine(); exist=new int[5]; System.out.println(getmax(str+str)); } } }
点赞 评论

相关推荐

不愿透露姓名的神秘牛友
07-23 18:25
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-24 13:39
在记录秋招的大魔王很...:别被忽悠了,我做了多年销售。我可以告诉你,这就是忽悠你的,销售一定要看底薪也要看提成两者不可缺一。提成是有业绩的时候才拿的到的,谁能保证一直有单状态都好。销售有时候很讲究运气的。底薪是你这个人这个岗位日常工作体现的价值。别小看底薪,你看那些跳槽去做经理主管的,底薪底一些,人家愿意去吗?所以那些说销售靠提成的纯属忽悠,除非他们的业务很容易成单。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务