Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class _3_WeirdStrings {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String inputLine = input.nextLine();
- String noSym = inputLine.replaceAll("[\\/()| ]+","");
- String[] words = noSym.split("[^a-zA-Z]+");
- int[] sums = new int[words.length];
- for (int index = 0; index < words.length; index++) {
- for (char letter: words[index].toLowerCase().toCharArray()) {
- switch (letter) {
- case 'a': sums[index] += 1; break;
- case 'b': sums[index] += 2; break;
- case 'c': sums[index] += 3; break;
- case 'd': sums[index] += 4; break;
- case 'e': sums[index] += 5; break;
- case 'f': sums[index] += 6; break;
- case 'g': sums[index] += 7; break;
- case 'h': sums[index] += 8; break;
- case 'i': sums[index] += 9; break;
- case 'j': sums[index] += 10; break;
- case 'k': sums[index] += 11; break;
- case 'l': sums[index] += 12; break;
- case 'm': sums[index] += 13; break;
- case 'n': sums[index] += 14; break;
- case 'o': sums[index] += 15; break;
- case 'p': sums[index] += 16; break;
- case 'q': sums[index] += 17; break;
- case 'r': sums[index] += 18; break;
- case 's': sums[index] += 19; break;
- case 't': sums[index] += 20; break;
- case 'u': sums[index] += 21; break;
- case 'v': sums[index] += 22; break;
- case 'w': sums[index] += 23; break;
- case 'x': sums[index] += 24; break;
- case 'y': sums[index] += 25; break;
- case 'z': sums[index] += 26; break;
- default:
- break;
- }
- }
- }
- String print = "";
- int maxSum = 0;
- for (int index = 0; index < sums.length-1; index++) {
- int sum = sums[index] + sums[index+1];
- String word1 = words[index];
- String word2 = words[index+1];
- if (sum>maxSum) {
- maxSum = sum;
- print = word1 + "\n" + word2;
- }
- }
- System.out.println(print);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement