Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- //Split string to array
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String[] input = reader.readLine().split("[^a-z0-9]+|(?<=[a-z])(?=[0-9])|(?<=[0-9])(?=[a-z])");
- Integer count = 0;
- Integer tmp2 = 0;
- Integer tmp1 = Integer.valueOf(input[0]);
- for (int i = 0; i < input.length - 2; i +=2 ){
- tmp2 = Integer.valueOf(input[i + 2]);
- //plus
- if (input[i + 1].length() % 2 == 0) {
- count = tmp1 + tmp2;
- }//minus
- if (input[i + 1].length() % 2 != 0) {
- count = tmp1 - tmp2;
- }
- tmp1 = count;
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement