114 lines
2.9 KiB
Java
114 lines
2.9 KiB
Java
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
import java.util.Scanner;
|
||
|
|
||
|
/**
|
||
|
* @author 令照辉 [zeekling@163.com]
|
||
|
* @version 1.0
|
||
|
* @apiNote
|
||
|
* @since 2020-03-01
|
||
|
*/
|
||
|
public class HePai {
|
||
|
|
||
|
private static final int[] arr = {2, 5, 8, 11, 14};
|
||
|
|
||
|
private static final Character[] nums = {'0','1','2','3','4','5','6','7','8','9'};
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
Scanner sc = new Scanner(System.in);
|
||
|
while (sc.hasNext()){
|
||
|
String s = sc.nextLine();
|
||
|
if (s.length() > 15 ){
|
||
|
System.out.println("no");
|
||
|
continue;
|
||
|
}
|
||
|
boolean t1 = false;
|
||
|
for (int a: arr){
|
||
|
if (a == s.length()){
|
||
|
t1 = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if (!t1){
|
||
|
System.out.println("no");
|
||
|
continue;
|
||
|
}
|
||
|
Map<Character, Integer> map = new HashMap<>();
|
||
|
for (int i=0;i< s.length();i++){
|
||
|
Character c = s.charAt(i);
|
||
|
Integer num = map.getOrDefault(c, 0);
|
||
|
num +=1;
|
||
|
map.put(c, num);
|
||
|
}
|
||
|
|
||
|
System.out.println(isHePei(map) ? "yes" : "no");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static boolean isHePei(Map<Character, Integer> map){
|
||
|
|
||
|
Map<Character, Integer> mapBak = null;
|
||
|
|
||
|
for (Map.Entry<Character, Integer> entry: map.entrySet()){
|
||
|
Character curr = entry.getKey();
|
||
|
Integer num = entry.getValue();
|
||
|
if (num > 4){
|
||
|
return false;
|
||
|
}else {
|
||
|
mapBak = new HashMap<>(map);
|
||
|
mapBak.put(curr, num -2);
|
||
|
if (isKOrShun(mapBak)){
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
private static boolean isKOrShun(Map<Character, Integer> map){
|
||
|
|
||
|
Character pre = null;
|
||
|
int lianxu = 0;
|
||
|
int preCiShu = 0;
|
||
|
for (int i=0;i<nums.length;i++){
|
||
|
Character c = nums[i];
|
||
|
Integer num = map.get(c);
|
||
|
if (num == null){
|
||
|
continue;
|
||
|
}
|
||
|
if (num == 3 || num == 0){
|
||
|
map.remove(c);
|
||
|
pre = null;
|
||
|
lianxu = 0;
|
||
|
preCiShu = 0;
|
||
|
continue;
|
||
|
}
|
||
|
if (pre == null){
|
||
|
pre = c;
|
||
|
lianxu +=1;
|
||
|
preCiShu = num;
|
||
|
map.remove(c);
|
||
|
continue;
|
||
|
}
|
||
|
if (preCiShu != num){
|
||
|
return false;
|
||
|
}
|
||
|
if (c - pre > 1){
|
||
|
return false;
|
||
|
}
|
||
|
pre = c;
|
||
|
lianxu += 1;
|
||
|
map.remove(c);
|
||
|
if (lianxu == 3){
|
||
|
pre = null;
|
||
|
lianxu = 0;
|
||
|
preCiShu = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return map.size() == 0;
|
||
|
}
|
||
|
|
||
|
}
|