Advertisement
Stephen_MS

SequenceOfEqualStrings

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