Click
Here to go back to the homepage.
DRM Messages Solution:
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Kattis {
public static void main(String[] args) {
String line = new Scanner(System.in).nextLine();
StringBuilder sb = new StringBuilder();
String[] firstPart = line.substring(0, line.length() /2).split("");
String[] secondPart = line.substring(line.length() /2, line.length()).split("");
int firstRotate = Arrays.stream(firstPart).mapToInt(i -> i.charAt(0) - 'A').sum();
int secondRotate = Arrays.stream(secondPart).mapToInt(i -> i.charAt(0) - 'A').sum();
Arrays.stream(firstPart).map((String s) -> rotate(s.charAt(0), firstRotate)).collect(Collectors.toList()).toArray(firstPart);
Arrays.stream(secondPart).map((String s) -> rotate(s.charAt(0), secondRotate)).collect(Collectors.toList()).toArray(secondPart);
IntStream.range(0, firstPart.length).forEach(i -> sb.append(rotate(firstPart[i].charAt(0), secondPart[i].charAt(0) - 'A')));
System.out.println(sb);
}
static String rotate(char e, int rotate){
return Character.toString((char)((e - 'A' + rotate) % 26 + 'A'));
}
}