Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class _02_SequencesOfEqualStrings {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] allWords = sc.nextLine().split(" ");
- Map<String, Integer> wordCounter = new HashMap<String, Integer>();
- for (String word : allWords) {
- Integer count = wordCounter.get(word);
- if(count == null){
- count = 0;
- }
- wordCounter.put(word, count + 1);
- }
- for(String word : wordCounter.keySet()){
- int count = wordCounter.get(word);
- for (int i = 0; i < count; i++) {
- System.out.printf("%s ", word);
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment