Advertisement
tockata

03. Weird Strings

Sep 21st, 2014
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class _03 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         String text = input.nextLine().replaceAll("[\\\\/\\|\\(\\)\\s]+", "");
  10.         String[] words = text.split("[^A-Za-z]+");
  11.         String alphabet = "abcdefghijklmnopqrstuvwxyz";
  12.         ArrayList<Integer> sums = new ArrayList<>();
  13.  
  14.         int maxSum = 0;
  15.         int maxStartIndex = 0;
  16.         int sum = 0;
  17.        
  18.         for (String word : words) {
  19.             word = word.toLowerCase();
  20.             for (int i = 0; i < word.length(); i++) {
  21.                 sum += alphabet.indexOf(word.charAt(i) + 1);
  22.             }
  23.             sums.add(sum);
  24.             sum = 0;
  25.         }
  26.        
  27.         for (int i = 0; i < sums.size() - 1; i++) {
  28.             sum = sums.get(i) + sums.get(i + 1);
  29.             if (sum >= maxSum) {
  30.                 maxSum = sum;
  31.                 maxStartIndex = i;
  32.                 sum = 0;
  33.             }
  34.         }
  35.         System.out.println(words[maxStartIndex]);
  36.         System.out.println(words[maxStartIndex + 1]);
  37.  
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement