1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #288 (Arithmetic Operations With Large Integers)
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=4&page=show_problem&problem=224
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 05/19/2009
*
* Status : Accepted
* Runtime: 0.320
*/
import java.text.BreakIterator;
import java.util.ArrayList;
import java.io.*;
import java.math.BigInteger;

public class Main
{

@SuppressWarnings("unchecked")
public static void main(String... args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
StringBuilder builder = new StringBuilder();
String line;
BreakIterator iterator = BreakIterator.getWordInstance();
Object[] analysis;
ArrayList<BigInteger> numbers = new ArrayList<BigInteger>();
ArrayList<String> operands = new ArrayList<String>();
BigInteger result;

while(true)
{
line = reader.readLine();

if(line == null || line.isEmpty())
break;

iterator.setText(line);
analysis = getLineAnalysis(iterator, line);
numbers = (ArrayList<BigInteger>)analysis[0];
operands = (ArrayList<String>)analysis[1];

//handling of power-operation as ranked highest priority.
for(int i=0;i<operands.size();i++)
{
String op = operands.get(i);
if(op.equals("**"))
{
numbers.set(i, (math(numbers.get(i),numbers.get(i+1),op)));
numbers.remove(i+1);
operands.remove(i);
i--;
}
}

//handling of multiplication-operation as ranked second highest priority.
for(int i=0;i<operands.size();i++)
{
String op = operands.get(i);
if(op.equals("*"))
{
numbers.set(i, (math(numbers.get(i),numbers.get(i+1),op)));
numbers.remove(i+1);
operands.remove(i);
i--;
}
}

//calculate the rest
result = numbers.get(0);
for(int i=0;i<operands.size();i++)
result = math(result,numbers.get(i+1),operands.get(i));


builder.append(result.toString() + "\n");
}

System.out.print(builder.toString());
}

/**
* getLineAnalysis
*
* This methods splits a line of numbers and operation signs into their parts. You'll get numbers on the one hand,
* and operation signs on the other.
*
* @param iterator represents a BreakIterator. Should be a WordInstanceIterator
* @param source represents the String, which shall be analysed
* @return Object[] with the following index:
* [0]: ArrayList of BigInteger having all numbers of the string in order
* [1]: ArrayList of Strings having all operation signs.
* size of [1] is size of [0]-1.
*/
public static Object[] getLineAnalysis(BreakIterator iterator, String source)
{
Object[] result = new Object[2];
ArrayList<BigInteger> numbers = new ArrayList<BigInteger>();
ArrayList<String> operands = new ArrayList<String>();

//jumper indicates, whether a number or a operation sign follows next
boolean jumper = true;

int start = iterator.first();
for (int end = iterator.next(); end != BreakIterator.DONE; start = end, end = iterator.next())
{
if(jumper)
{
String substring = source.substring(start,end);

//the switch has to be in order to catch "**"
if(substring.length()==1 && (substring.charAt(0)<'0' || substring.charAt(0)>'9'))
operands.set(operands.size()-1, operands.get(operands.size()-1) + substring);
else
{
numbers.add(new BigInteger(substring));
jumper = false;
}
}
else
{
String substring = source.substring(start,end);
operands.add(substring);
jumper = true;
}
}

result[0] = numbers;
result[1] = operands;

return result;
}

/**
* math
*
* This method calculates two numbers according to its operation sign.
*
* @param a is the first BigInteger of the operation
* @param b is the second BigInteger of the operation
* @param op is the operation sign. Has to be +, -, * or **(for power)
* @return BigInteger with the result of the operation or 0, when operation sign was invalid.
*/
public static BigInteger math(BigInteger a, BigInteger b, String op)
{
BigInteger result;

if(op.equals("+"))
result = a.add(b);
else if(op.equals("-"))
result = a.subtract(b);
else if(op.equals("*"))
result = a.multiply(b);
else if(op.equals("**"))
result = a.pow(b.intValue());
else
result = BigInteger.ZERO;

return result;
}

}