Exemple #1
0
  private static void handleInput() throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = null;
    int testCases = -1;
    while (null != (line = br.readLine())) {
      if (testCases == -1) {
        testCases = Integer.parseInt(line);
        continue;
      }
      BigNumber b1 = null;
      BigNumber b2 = null;
      BigNumber res = null;
      BigNumber[] resArr = null;
      if (line.split("-").length > 1) {
        String[] substr = line.split("-");
        b1 = new BigNumber(substr[0]);
        b2 = new BigNumber(substr[1]);
        res = b1.subtract(b2);
        BigNumber.formatOp(b1, b2, res, "-");
      } else if (line.split("\\*").length > 1) {
        String[] mult = line.split("\\*");
        b1 = new BigNumber(mult[0]);
        b2 = new BigNumber(mult[1]);
        resArr = b1.multiply(b2);
        BigNumber.formatMult(b1, b2, resArr);
      } else if (line.split("\\+").length > 1) {
        String[] add = line.split("\\+");
        b1 = new BigNumber(add[0]);
        b2 = new BigNumber(add[1]);
        res = b1.add(b2);
        BigNumber.formatOp(b1, b2, res, "+");
      }

      System.out.println();
      if (--testCases <= 0) break;
    }
  }
Exemple #2
0
  private static void testOperations() {
    BigNumber bn1 = null;
    BigNumber bn2 = null;
    BigNumber res = null;

    bn1 = new BigNumber("1");
    bn2 = new BigNumber("10");
    res = bn1.add(bn2);
    BigNumber.formatOp(bn1, bn2, res, "+");

    System.out.println();

    bn1 = new BigNumber("1");
    bn2 = new BigNumber("1");
    res = bn1.subtract(bn2);
    BigNumber.formatOp(bn1, bn2, res, "-");

    System.out.println();

    bn1 = new BigNumber("35");
    bn2 = new BigNumber("111111111");
    BigNumber[] resArr = bn1.multiply(bn2);
    BigNumber.formatMult(bn1, bn2, resArr);
  }