Advertisement
nmnikolov

JavaExam21Sep_03_WeirdStrings

Sep 22nd, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class _03_WeirdStrings {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);        
  8.         String line = input.nextLine().replaceAll("[\\/()| ]+", "");
  9.         String[] words = line.split("[^a-zA-Z]+");
  10.         int[] weights = new int[words.length];
  11.                
  12.         int max = Integer.MIN_VALUE;
  13.         String max1Value = "";
  14.         String max2Value = "";
  15.        
  16.         for (int i = 0; i < words.length; i++) {
  17.             weights[i] = checkWeight(words[i]);
  18.         }
  19.        
  20.         for (int i = 0; i < weights.length - 1; i++) {
  21.             int weight = weights[i] + weights[i + 1];
  22.             if (weight >= max) {
  23.                 max1Value = words[i];
  24.                 max2Value = words[i + 1];
  25.                 max = weight;
  26.             }
  27.         }      
  28.         System.out.println(max1Value);
  29.         System.out.println(max2Value);
  30.     }
  31.  
  32.     public static int checkWeight (String s){
  33.         int weight = 0;
  34.         s = s.toLowerCase();
  35.        
  36.         for (int i = 0; i < s.length(); i++) {
  37.             weight += Character.getNumericValue(s.charAt(i)) - 9;
  38.         }
  39.        
  40.         return weight;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement