Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class _03_WeirdStrings {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String line = input.nextLine().replaceAll("[\\/()| ]+", "");
- String[] words = line.split("[^a-zA-Z]+");
- int[] weights = new int[words.length];
- int max = Integer.MIN_VALUE;
- String max1Value = "";
- String max2Value = "";
- for (int i = 0; i < words.length; i++) {
- weights[i] = checkWeight(words[i]);
- }
- for (int i = 0; i < weights.length - 1; i++) {
- int weight = weights[i] + weights[i + 1];
- if (weight >= max) {
- max1Value = words[i];
- max2Value = words[i + 1];
- max = weight;
- }
- }
- System.out.println(max1Value);
- System.out.println(max2Value);
- }
- public static int checkWeight (String s){
- int weight = 0;
- s = s.toLowerCase();
- for (int i = 0; i < s.length(); i++) {
- weight += Character.getNumericValue(s.charAt(i)) - 9;
- }
- return weight;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement