UVA 787 - Maximum Sub-sequence Product

UVA Sep 1, 2020

Problem PDF

Solution:

package pkg787;

import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    private static String line;
    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
    ArrayList a = new ArrayList();
    BigInteger n;
    
    while (in.hasNext()) {
      
      n = in.nextBigInteger();
      if (n.compareTo(BigInteger.valueOf(-999999))==0)
      {
        BigInteger result = a.get(0);
        BigInteger pro;
        for (int i = 0; i < a.size(); i ++) {
          pro =BigInteger.ONE;
          for(int j=i;j < a.size();j++) {
            pro = pro.multiply(a.get(j));
            if (result.compareTo(pro) == -1) 
                result = pro;
 
          }
        }
        a.clear();
        System.out.println(result);
      }
      else
      {
          a.add(n);
      }
    }
    }
    
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/787/Main.java

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.