Advertisement
Macphisto1911

Letters Change Numbers

Jul 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         // write your code here
  9.         Scanner scanner = new Scanner(System.in);
  10.         String [] strings = scanner.nextLine().split("\\s+");
  11.  
  12.         double sum = 0;
  13.  
  14.         for (String string : strings) {
  15.             char before = string.charAt(0);
  16.             char after = string.charAt(string.length()-1);
  17.  
  18.             long number = Long.parseLong(string.substring(1, string.length() - 1));
  19.             sum += calcCurrentValue(before, after, number);
  20.  
  21.         }
  22.         System.out.printf("%.2f", sum);
  23.     }
  24.     private static double calcCurrentValue(char before, char after, long number){
  25.         double value = 0;
  26.  
  27.         if (Character.isUpperCase(before)){
  28.             value += (number * 1.00) / (before - 'A' +1) ;
  29.  
  30.         }else {
  31.             value += number * (before - 'a' +1);
  32.  
  33.         }
  34.         if (Character.isUpperCase(after)){
  35.             value -= (after - 'A' +1);
  36.  
  37.         }else {
  38.             value += (after - 'a' +1);
  39.  
  40.         }
  41.         return value;
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement