Guest User

Untitled

a guest
May 24th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Map.Entry;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class _03_LargestSequenceOfEqualStrings {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner sc = new Scanner(System.in);
  12.        
  13.         String[] allWords = sc.nextLine().split(" ");
  14.        
  15.         Map<String, Integer> wordCounter = new HashMap<String, Integer>();
  16.        
  17.         for (String word : allWords) {
  18.             Integer count = wordCounter.get(word);
  19.             if(count == null){
  20.                 count = 0;
  21.             }
  22.             wordCounter.put(word, count + 1);
  23.         }
  24.        
  25.         Entry<String,Integer> maxEntry = null;
  26.  
  27.         for(Entry<String,Integer> entry : wordCounter.entrySet()) {
  28.             if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
  29.                 maxEntry = entry;
  30.             }
  31.         }
  32.        
  33.         for (int i = 0; i < maxEntry.getValue(); i++) {
  34.             System.out.printf("%s ", maxEntry.getKey());
  35.         }
  36.     }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment