fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5.  
  6. final class Seq {
  7. public static String FindMax(String s){
  8. int t, j, i = 0, n = 0, p = -1;
  9.  
  10. while(i < s.length()){
  11. while((i < s.length()) && ! Character.isDigit(s.charAt(i)))
  12. ++i;
  13.  
  14. j = i + 1;
  15. while((j < s.length()) && (Character.isDigit(s.charAt(j)) ||
  16. Character.isSpaceChar(s.charAt(j))))
  17. ++j;
  18.  
  19. t = j;
  20. if(j < s.length()){
  21. while ((j > i) && Character.isSpaceChar(s.charAt(j)))
  22. --j;
  23. }
  24.  
  25. if((j - i) > n){
  26. n = j - i;
  27. p = i;
  28. }
  29. i = t;
  30. }
  31. return (p != -1) ? s.substring(p, p + n) : null;
  32. }
  33. }
  34.  
  35.  
  36. class Project {
  37. public static void main (String[] args){
  38. String s = "bla-bla 129 349 56 sequence 123 456 789 end";
  39.  
  40. String res = Seq.FindMax(s);
  41. if(res != null)
  42. System.out.println(res);
  43. else
  44. System.out.println("Галяк, ничего не найдено товарищ!");
  45. }
  46. }
Success #stdin #stdout 0.09s 320256KB
stdin
Standard input is empty
stdout
123 456 789