Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Sun26062011;
- import java.util.*;
- import java.io.*;
- public class ProblemC
- {
- public static void main(String[] args) throws FileNotFoundException
- {
- Scanner sc = new Scanner(new File("src/Sun26062011/ProbCText.txt"));
- int longestSize = 0;
- String longestWord = "";
- while(sc.hasNext())
- {
- String s = sc.next();
- if(s.equals("E-N-D"))
- {
- break;
- }
- int size = checkSize(s);
- if(size > longestSize)
- {
- longestSize = size;
- longestWord = s;
- }
- }
- System.out.println(longestWord);
- }
- private static int checkSize(String s)
- {
- String s2 = s.trim();
- s2 = clearSymbol(s2,"-");
- s2 = clearSymbol(s2,".");
- s2 = clearNumber(s2);
- return s2.length();
- }
- private static String clearNumber(String s)
- {
- for (int i = 0 ; i < s.length() ; i++)
- {
- if(Character.isDigit(s.charAt(i)))
- {
- s = s.substring(0,i) + s.substring(i+1);
- i--;
- }
- }
- return s;
- }
- private static String clearSymbol(String s,String s2)
- {
- int idx = -1;
- while((idx = s.indexOf(s2))!=-1)
- {
- s = s.substring(0,idx) + s.substring(idx+1);
- }
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement