svetlozar_kirkov

Letters Change Numbers

May 8th, 2015
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.         Scanner input = new Scanner(System.in);
  11.         String[] inputLine = input.nextLine().split("\\s+");
  12.         double sum = 0;
  13.         for (int i = 0; i < inputLine.length; i++) {
  14.             double tempNum = 0;
  15.             Pattern numPattern = Pattern.compile("-?\\d+");
  16.             Matcher numMatcher = numPattern.matcher(inputLine[i]);
  17.             while (numMatcher.find()) {
  18.                 tempNum = Double.parseDouble(numMatcher.group());
  19.             }
  20.             if (Character.isUpperCase(inputLine[i].charAt(0))) {
  21.                 tempNum = tempNum / ((int)(inputLine[i].charAt(0)) - 64);
  22.             }
  23.             else {
  24.                 tempNum = tempNum * ((int)(inputLine[i].charAt(0)) - 96);
  25.             }
  26.             if (Character.isUpperCase(inputLine[i].charAt(inputLine[i].length()-1))) {
  27.                 tempNum = tempNum - ((int)(inputLine[i].charAt(inputLine[i].length()-1)) - 64);
  28.             }
  29.             else {
  30.                 tempNum = tempNum + ((int)(inputLine[i].charAt(inputLine[i].length()-1)) - 96);
  31.             }
  32.             sum += tempNum;
  33.         }
  34.         System.out.printf("%.2f", sum);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment