Guest User

Untitled

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