fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. class Main {
  6. static long a[] = new long[6000];
  7. static long b[] = new long[6000];
  8. static long xx,yy,x,y,k,ans;
  9. static int i,j,m,n;
  10. static String s,t;
  11. static void solve(int l, int r)
  12. {
  13. x = 0; y = a[l];
  14. for (int i = l; i < r; i++)
  15. if (b[i] == 1)
  16. {
  17. x += y; y = a[i+1];
  18. }
  19. else
  20. y *= a[i+1];
  21. }
  22. public static void main(String[] args) throws IOException{
  23. Scanner sc = new Scanner(System.in);//new File("input.txt"));
  24. PrintWriter pw = new PrintWriter(System.out);//new File("output.txt"));
  25. s = sc.next();
  26. t = "1*";
  27. t = t.concat(s);
  28. t = t.concat("*1");
  29. s = t;
  30. n = s.length();
  31. m = n/2;
  32. for (i = 0; i < n; i+=2)
  33. a[i/2] = (int)s.charAt(i) - (int)'0';
  34. for (i = 1; i < n; i+=2)
  35. if (s.charAt(i) == '+')
  36. b[i/2] = 1;
  37. else
  38. b[i/2] = 2;
  39. long max1 = 0;
  40. for (i = 0; i < m; i++)
  41. for (j = i+1; j < m; j++)
  42. if (b[i] == 2 && b[j] == 2)
  43. {
  44. solve(0,i);
  45. xx = x; yy = y;
  46. solve(i+1,j);
  47. yy *= x + y;
  48. long xxx = a[j];
  49. a[j] = yy;
  50. solve(j,m);
  51. max1 = Math.max(max1, xx+x+y);
  52. a[j] = xxx;
  53. }
  54. pw.println(max1);
  55. pw.close();
  56. }
  57. }
  58.  
Runtime error #stdin #stdout #stderr 0.08s 380672KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:907)
	at java.util.Scanner.next(Scanner.java:1416)
	at Main.main(Main.java:25)