Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public class HelloWorld {
  2. private static int f(int[] a, int low, int high) {
  3. int res = 0;
  4. for (int i = low; i <= high; i++)
  5. res += a[i];
  6. return res;
  7. }
  8. public static int what(int[] a) {
  9. int temp = 0;
  10. for (int i = 0; i < a.length; i++) {
  11. for (int j = i; j < a.length; j++) {
  12. int c = f(a, i, j);
  13. if (c % 3 == 0) {
  14. if (j - i + 1 > temp)
  15. temp = j - i + 1;
  16. }
  17. }
  18. }
  19. return temp;
  20. }
  21.  
  22. public static void main(String[] args) {
  23.  
  24. int[] a = {
  25. 1,
  26. 2,
  27. 3,
  28. 4,
  29. 5,
  30. 6,
  31. 7,
  32. 8,
  33. 9,
  34. 11,
  35. 13,
  36. 15
  37. };
  38.  
  39.  
  40. int temp = 0;
  41. int sum = 0;
  42. for (int i = 0; i < a.length; i++) {
  43. sum += a[i];
  44.  
  45. if (sum % 3 == 0) {
  46. temp = i + 1;
  47. }
  48. }
  49.  
  50. System.out.println(temp);
  51. System.out.println(what(a));
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement