Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.  
  8. private static ArrayList<Integer> sequence = new ArrayList<>();
  9. private static int sum;
  10. private static int length;
  11.  
  12. public static void main(String[] args) throws IOException {
  13. Scanner sc = new Scanner(new File("C:\\Users\\adamk\\Desktop\\input.txt"));
  14.  
  15. while (sc.hasNextInt()) {
  16. sequence.add(sc.nextInt());
  17. }
  18.  
  19. for (int i = 0; i < sequence.size(); i++) {
  20. sequenceComparator(descending(i), i);
  21. sequenceComparator(ascending(i), i);
  22. }
  23. System.out.println(length + " " + sum);
  24. }
  25.  
  26. private static int ascending(int j) {
  27. int ascLength = 1;
  28. for (int i = j; i < sequence.size() - 1; i++) {
  29. if (sequence.get(i) <= sequence.get(i + 1)) {
  30. ascLength++;
  31. } else
  32. break;
  33. }
  34.  
  35. return ascLength;
  36. }
  37.  
  38. private static int descending(int j) {
  39. int descLength = 1;
  40. for (int i = j; i < sequence.size() - 1; i++) {
  41. if (sequence.get(i) >= sequence.get(i + 1)) {
  42. descLength++;
  43. } else
  44. break;
  45. }
  46.  
  47. return descLength;
  48. }
  49.  
  50. private static void sequenceComparator(int length, int index) {
  51. if (Main.length < length) {
  52. Main.length = length;
  53. sum = 0;
  54. for (int j = index; j < Main.length + index; j++) {
  55. sum += sequence.get(j);
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement