Pete1

Untitled

Mar 25th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 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. }
  30. if (bestSequenceLength < 0){
  31. System.out.println(input[0]);
  32. }
  33.  
  34. for (int i = sequenceStartIndex; i < bestSequenceLength + sequenceStartIndex; i++) {
  35. System.out.print(input[i] + " ");
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment