Advertisement
Guest User

LetterExpresion

a guest
Oct 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) throws IOException {
  11.  
  12.         //Split string to array
  13.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  14.         String[] input = reader.readLine().split("[^a-z0-9]+|(?<=[a-z])(?=[0-9])|(?<=[0-9])(?=[a-z])");
  15.  
  16.         Integer count = 0;
  17.         Integer tmp2 = 0;
  18.         Integer tmp1 = Integer.valueOf(input[0]);
  19.         for (int i = 0; i < input.length - 2; i +=2 ){
  20.             tmp2 = Integer.valueOf(input[i + 2]);
  21.             //plus
  22.             if (input[i + 1].length() % 2 == 0) {
  23.                 count = tmp1 + tmp2;
  24.  
  25.             }//minus
  26.             if (input[i + 1].length() % 2 != 0) {
  27.                 count = tmp1 - tmp2;
  28.             }
  29.             tmp1 = count;
  30.  
  31.         }
  32.         System.out.println(count);
  33.  
  34.     }
  35.  
  36.  
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement