Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String[] inputLine = input.nextLine().split("\\s+");
- double sum = 0;
- for (int i = 0; i < inputLine.length; i++) {
- double tempNum = 0;
- Pattern numPattern = Pattern.compile("-?\\d+");
- Matcher numMatcher = numPattern.matcher(inputLine[i]);
- while (numMatcher.find()) {
- tempNum = Double.parseDouble(numMatcher.group());
- }
- if (Character.isUpperCase(inputLine[i].charAt(0))) {
- tempNum = tempNum / ((int)(inputLine[i].charAt(0)) - 64);
- }
- else {
- tempNum = tempNum * ((int)(inputLine[i].charAt(0)) - 96);
- }
- if (Character.isUpperCase(inputLine[i].charAt(inputLine[i].length()-1))) {
- tempNum = tempNum - ((int)(inputLine[i].charAt(inputLine[i].length()-1)) - 64);
- }
- else {
- tempNum = tempNum + ((int)(inputLine[i].charAt(inputLine[i].length()-1)) - 96);
- }
- sum += tempNum;
- }
- System.out.printf("%.2f", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment