Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 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.            
  25.            
  26.             int size = checkSize(s);
  27.            
  28.             if(size > longestSize)
  29.             {
  30.                 longestSize = size;
  31.                 longestWord = s;
  32.             }
  33.         }
  34.        
  35.         System.out.println(longestWord.toLowerCase());
  36.     }
  37.  
  38.     private static int checkSize(String s)
  39.     {
  40.         String s2 = s.trim();
  41.        
  42.         s2 = clearSymbol(s2,"-");
  43.         s2 = clearSymbol(s2,".");
  44.         s2 = clearNumber(s2);
  45.        
  46.         return s2.length();
  47.     }
  48.  
  49.     private static String clearNumber(String s)
  50.     {
  51.         for (int i = 0 ; i < s.length() ; i++)
  52.         {
  53.             if(Character.isDigit(s.charAt(i)))
  54.             {
  55.                 s = s.substring(0,i) + s.substring(i+1);
  56.                 i--;
  57.             }
  58.         }
  59.        
  60.         return s;
  61.     }
  62.  
  63.     private static String clearSymbol(String s,String s2)
  64.     {
  65.         int idx = -1;
  66.         while((idx = s.indexOf(s2))!=-1)
  67.         {
  68.             s = s.substring(0,idx) + s.substring(idx+1);
  69.         }
  70.         return s;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement