// UVa 465 - Overflow
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] tokens = line.split(" ");
String sa = tokens[0];
String sb = tokens[tokens.length - 1];
char operator = '?';
for (int i = 1; i < tokens.length - 1; i++)
if (!tokens[i].equals("")) {
operator = tokens[i].charAt(0);
break;
}
BigInteger a = new BigInteger(sa);
BigInteger b = new BigInteger(sb);
BigInteger c = (operator == '+')
? a.add(b)
: a.multiply(b);
System.out.println(line);
warnIfNecessary("first number", a);
warnIfNecessary("second number", b);
warnIfNecessary("result", c);
}
}
private static final BigInteger LIMIT = BigInteger.valueOf(Integer.MAX_VALUE);
private static void warnIfNecessary(String prefix, BigInteger number) {
if (number.compareTo(LIMIT) > 0) {
System.out.println(prefix + " too big");
}
}
}
Tuesday, October 29, 2019
UVa 465 - Overflow
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment