Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.Collections;
- import java.util.List;
- public class testSort {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner stdin = new Scanner(System.in);
- ArrayList<String> list = new ArrayList<String>();
- while (stdin.hasNext()) {
- int length = 0;
- int top = 0;
- int freq = 0;
- String key = "fail";
- try {
- length = Integer.parseInt(args[0]);
- }catch(Exception e){
- length = 5;
- }
- String[] possibleWords =
- stdin.next().replaceAll("(^[^A-Za-z]+)|([^A-Za-z]+$)", "").split("-");
- for(int i = 0; i < possibleWords.length; i++) {
- list.add(possibleWords[i]);
- }
- list.sort(null);
- for (int i = 0; i < list.size(); i++) {
- freq = Collections.frequency(list, list.get(i));
- if(freq > top && list.get(i).length() > length) {
- top = freq;
- key = list.get(i);
- //System.out.printf("index %d",i);
- }
- }
- System.out.printf("%s %d%n", key, top);
- }
- //System.out.println(list);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement