Pete1

Untitled

Apr 2nd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. package CollectionsHomework;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Problem3LargestSequenceOfEqualString {
  6. public static void main(String[] args) {
  7. Scanner console = new Scanner(System.in);
  8.  
  9. String[] input = console.nextLine().split(" ");
  10. int sequenceLength = 1;
  11. int sequenceStartIndex = 0;
  12. int bestSequenceLength = -50;
  13.  
  14. for (int i = 1; i < input.length; i++) {
  15. if (input[i].equals(input[i - 1])) {
  16. sequenceLength++;
  17. if (sequenceLength > bestSequenceLength) {
  18. bestSequenceLength = sequenceLength;
  19. sequenceStartIndex = i - bestSequenceLength + 1;
  20. }
  21. } else {
  22. sequenceLength = 1;
  23.  
  24. }
  25.  
  26.  
  27. }
  28. if (bestSequenceLength < 0) {
  29. System.out.println(input[0]);
  30. }
  31.  
  32. for (int i = sequenceStartIndex; i < bestSequenceLength + sequenceStartIndex; i++) {
  33. System.out.print(input[i] + " ");
  34.  
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment