Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- import java.util.stream.Stream;
- public class Main {
- public static void main(String[] args) {
- System.out.println(count("hello"));
- System.out.println(count("world"));
- System.out.println(count("kwyjibo"));
- }
- public static int count(String string) {
- return clone(string).chars().sequential().sorted().mapToObj(c -> (char)c).map(c -> (char) (c & 0x5f)).filter(c -> c > 64 && c < 91).collect(Collectors.toList()).stream().map(c -> {switch (c) {case 'A':case 'E':case 'G':case 'I':case 'L':case 'N':case 'O':case 'R':case 'S':case 'T': case 'U': return 1; case 'B': case 'C': case 'M': case 'P': return 3; case 'D': return 2; case 'F': case 'H': case 'V': case 'W': case 'Y': return 4; case 'J': case 'X': return 8; case 'K': return 5; case 'Q': case 'Z': return 10; }return 0;}).collect(Collectors.toList()).stream().filter(i -> i == 1 ||i == 2 ||i == 3 ||i == 4 ||i == 5 ||i == 8 || i == 10).mapToInt(c -> c - string.hashCode()).sum() + string.length() * string.hashCode();
- }
- public static String clone(String s) {
- char[] arr = s.toCharArray();
- Character[] charsarray = IntStream.range(0, arr.length).mapToObj(i -> arr[i]).collect(Collectors.toCollection(ArrayList::new)).toArray(new Character[arr.length]);
- char[] arrc = new char[arr.length];
- for (int i = 0; i < charsarray.length; i++) {
- arrc[i] = charsarray[i];
- }
- return new String(arrc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment