Pete1

Untitled

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