牛客网小易喜欢的单词
2018-04-11 23:00
190 查看
牛客网小易喜欢的单词
超出时间import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Create by ~JH~ on 2018/4/11 */ public class Main{ public List<String> li=new ArrayList<>(); public boolean isLike(String str){ for(int i=0;i<str.length()-1;i++){ char c=str.charAt(i); if (c<65||c>90)return false; if(c==str.charAt(i+1)){ return false; } } return true; } public boolean childIsLike(String str){ if (str.length()==4&&str.charAt(0)==str.charAt(2)&&str.charAt(1)==str.charAt(3)){ return false; }else{ return true; } } public void getChild(List<String >list,String pre){ if (pre!=""&&pre.length()==4){ li.add(new String(pre)); System.out.println(pre); } for (int i=0;i<list.size();i++){ List <String >temp=new ArrayList<>(list); String s=temp.remove(i).toString(); getChild(temp.subList(i,temp.size()),pre+s); } } public static void main(String []args){ Main m=new Main(); Scanner sca=new Scanner(System.in); String str=sca.nextLine(); List<String>list=new ArrayList<>(); if(m.isLike(str)){ }else{ System.out.println("Dislikes"); return ; } for (int i=0;i<str.length();i++){ list.add(str.charAt(i)+""); } m.getChild(list,""); boolean flag=true; for (String l :m.li ) { if (!m.childIsLike(l)){ flag=false; } } if (flag){ System.out.println("Likes"); }else{ System.out.println("Dislikes"); } } }
相关文章推荐
- 小易喜欢的单词
- 算法题--小易喜欢的单词
- 小易喜欢的单词
- 网易—小易喜欢的单词
- 网易笔试编程-小易喜欢的单词
- 网易 小易喜欢的单词
- 网易笔试题:小易喜欢的单词
- 小易喜欢的单词
- 小易喜欢的单词具有以下特性: 1.单词每个字母都是大写字母 2.单词没有连续相等的字母 3.单词没有形如“xyxy”(这里的x,y指的都是字母,并且可以相同)这样的子序列,子序列可能不连续。 例如: 小易不喜欢"ABBA",因为这里有两个连续的'B' 小易不喜欢"THETXH",因为这里包含子序列"THTH" 小易不喜欢"ABACADA",因为这里包含子序列"AAAA" 小易喜欢"
- 算法---小易喜欢的单词
- 小易喜欢的单词
- 网易编程题——小易喜欢的单词
- 网易笔试编程题:小易喜欢的单词(C++)
- 网易2018校招内推编程题 小易喜欢的数列
- 华为机试在线训练-牛客网(19)【中级】单词倒排
- 8.12网易内推笔试题:小易喜欢的数列 java实现
- 牛客网华为机试在线训练字符串最后一个单词的长度
- 翻转单词顺序列(牛客网二十八)
- 网易2017内推 [编程题]小易喜欢的数列