Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package Sun26062011;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class ProblemC
  7. {
  8.     public static void main(String[] args) throws FileNotFoundException
  9.     {
  10.         Scanner sc = new Scanner(new File("src/Sun26062011/ProbCText.txt"));
  11.        
  12.         int longestSize = 0;
  13.         String longestWord = "";
  14.        
  15.         while(sc.hasNext())
  16.         {
  17.             String s = sc.next();
  18.            
  19.             if(s.equals("E-N-D"))
  20.             {
  21.                 break;
  22.             }
  23.            
  24.             int size = checkSize(s);
  25.            
  26.             if(size > longestSize)
  27.             {
  28.                 longestSize = size;
  29.                 longestWord = s;
  30.             }
  31.         }
  32.        
  33.         System.out.println(longestWord);
  34.     }
  35.  
  36.     private static int checkSize(String s)
  37.     {
  38.         String s2 = s.trim();
  39.         s2 = clearSymbol(s2,"-");
  40.         s2 = clearSymbol(s2,".");
  41.         s2 = clearNumber(s2);
  42.        
  43.         return s2.length();
  44.     }
  45.  
  46.     private static String clearNumber(String s)
  47.     {
  48.         for (int i = 0 ; i < s.length() ; i++)
  49.         {
  50.             if(Character.isDigit(s.charAt(i)))
  51.             {
  52.                 s = s.substring(0,i) + s.substring(i+1);
  53.                 i--;
  54.             }
  55.         }
  56.        
  57.         return s;
  58.     }
  59.  
  60.     private static String clearSymbol(String s,String s2)
  61.     {
  62.         int idx = -1;
  63.         while((idx = s.indexOf(s2))!=-1)
  64.         {
  65.             s = s.substring(0,idx) + s.substring(idx+1);
  66.         }
  67.         return s;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement